I'm trying to make my first program with cuda.
So I make this simple HelloWorld with guide of various pages.
#include <cstdlib>
#include <cstdio>
#include <cuda.h>
using namespace std;
__global__ void mykernel(void) {
}
int main(void) {
mykernel<<<1,1>>>();
printf("CPU Hello World!\n");
return 0;
}
But I am getting this output:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/hellowordcuda
make[2]: Entering directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/hellowordcuda.o.d"
g++ -c -g -I/usr/local/cuda-7.5/include -MMD -MP -MF "build/Debug/GNU-Linux-x86/hellowordcuda.o.d" -o build/Debug/GNU-Linux-x86/hellowordcuda.o hellowordcuda.cpp
hellowordcuda.cpp:19:1: error: ‘__global__’ does not name a type
__global__ void mykernel(void) {
^
hellowordcuda.cpp: In function ‘int main()’:
hellowordcuda.cpp:24:1: error: ‘mykernel’ was not declared in this scope
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:11: error: expected primary-expression before ‘<’ token
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:17: error: expected primary-expression before ‘>’ token
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:19: error: expected primary-expression before ‘)’ token
mykernel<<<1,1>>>();
^
make[2]: *** [build/Debug/GNU-Linux-x86/hellowordcuda.o] Error 1
make[2]: Leaving directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
make: *** [.build-impl] Error 2
I'm sorry for making a question so simple but I just don't find any answer for this.
Thanks a lot, any help would be greatly appreciated!
There are two things you need to do to make this work:
use the CUDA compiler driver nvcc to steer compilation of the code
rename hellowordcuda.cpp to hellowordcuda.cu when passing the code to nvcc
The second point is necessary because nvcc uses the file extension to steer compilation, and if you code has a .cc or .cpp file extension, it will just pass the code to the host compiler and the same compilation errors will result
In guide also below lines are mentioned,
$ nvcc hello.cu
$ a.out
Hello World!
Please change g++ to nvcc in your Makefile.
It appears you're building directly with g++. You need to use NVidia's compiler (nvcc) to use CUDA, and make sure it knows to process the file as CUDA C. This can be achieved by changing the extension to .cu, or by playing around with compilation options which specify the file & processing type. I recommend the former.
Related
I'm tring to compile a simple armadillo program by netbeans and msys2:
#include <cstdlib>
#include <armadillo>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
arma::Mat<double> A = arma::randu(4,4);
return 0;
}
I'm using netbeans 8.2, msys2 installed and configured with openblas and armadillo installed by pacman.
but I get this error:
cd 'D:\Users\Amir\Documents\NetBeansProjects\physics\CppApplication_2'
C:\msys64\usr\bin\make.exe -f Makefile CONF=Release
"/C/msys64/usr/bin/make.exe" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/d/Users/Amir/Documents/NetBeansProjects/physics/CppApplication_2'
"/C/msys64/usr/bin/make.exe" -f nbproject/Makefile-Release.mk dist/Release/MinGW-Windows/cppapplication_2.exe
make[2]: Entering directory '/d/Users/Amir/Documents/NetBeansProjects/physics/CppApplication_2'
mkdir -p build/Release/MinGW-Windows
rm -f "build/Release/MinGW-Windows/main.o.d"
g++ -c -O2 -std=c++11 -MMD -MP -MF "build/Release/MinGW-Windows/main.o.d" -o build/Release/MinGW-Windows/main.o main.cpp
In file included from C:/msys64/mingw64/include/armadillo:54,
from main.cpp:15:
C:/msys64/mingw64/include/armadillo_bits/compiler_setup.hpp:66:30: fatal error: C:/building/msys64/mingw64/include/hdf5.h: No such file or directory
#define ARMA_INCFILE_WRAP(x) <x>
^
compilation terminated.
make[2]: *** [nbproject/Makefile-Release.mk:68: build/Release/MinGW-Windows/main.o] Error 1
make[2]: Leaving directory '/d/Users/Amir/Documents/NetBeansProjects/physics/CppApplication_2'
make[1]: *** [nbproject/Makefile-Release.mk:59: .build-conf] Error 2
make[1]: Leaving directory '/d/Users/Amir/Documents/NetBeansProjects/physics/CppApplication_2'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2
BUILD FAILED (exit value 2, total time: 575ms)
I also installed hdf5 in msys2.
How can I get rid of this error?
thx.
it seems someone put this #define ARMA_HDF5_INCLUDE_DIR C:/building/msys64/mingw64/include/ into config.hpp in folder armadillo_bits. changing this to your usual include directory or setting it as nothing should fix the problem.
I'm (somewhat) new to C++ and I've been trying to get a program to work. It all compiles fine until I start to define a class constructor within the source file, even though I have declared it in the header file. I'm not sure if it's because I haven't defined all of my methods, because this is my second attempt at defining them (I'm literally rewriting them slowly to see if it helps).
The code in question is below (this is what is on the cpp file):
#include <cstdlib>
#include <iostream>
#include <string.h>
#include "StockItem.h"
Diode::Diode(char* componentT, char* code, int quantity, int price){
strcpy(componentType,componentT);
strcpy(stockCode,code);
stockQuantity = quantity;
unitPrice = price;
}
The output I receive is below:
cd 'G:\EDUCATION\University\Year 2\Year Courses\PROGRAMMING 2\Assignments\Assignment 2\COURSEWORK_100088688\StockProgram_C++'
C:\cygwin\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/stockprogram_c__.exe
make[2]: Entering directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/StockItem.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/Cygwin-Windows/StockItem.o.d" -o build/Debug/Cygwin-Windows/StockItem.o StockItem.cpp
StockItem.cpp: In member function 'void StockItem::setComponentType(char*)':
StockItem.cpp:27:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S1 = "resistor";
^
StockItem.cpp:28:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S2 = "capacitor";
^
StockItem.cpp:29:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S3 = "transistor";
^
StockItem.cpp:30:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S4 = "diode";
^
StockItem.cpp:31:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* S5 = "ic";
^
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/StockProgram.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/Cygwin-Windows/StockProgram.o.d" -o build/Debug/Cygwin-Windows/StockProgram.o StockProgram.cpp
mkdir -p dist/Debug/Cygwin-Windows
g++ -o dist/Debug/Cygwin-Windows/stockprogram_c__ build/Debug/Cygwin-Windows/StockItem.o build/Debug/Cygwin-Windows/StockProgram.o
build/Debug/Cygwin-Windows/StockItem.o: In function `ZN9StockItemC2Ev':
/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++/StockItem.h:8: undefined reference to `vtable for StockItem'
build/Debug/Cygwin-Windows/StockItem.o:StockItem.cpp:(.rdata$_ZTV5Diode[__ZTV5Diode]+0x8): undefined reference to `StockItem::getComponentInfo()'
build/Debug/Cygwin-Windows/StockItem.o:StockItem.cpp:(.rdata$_ZTV5Diode[__ZTV5Diode]+0xc): undefined reference to `StockItem::setComponentInfo(char*)'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:63: recipe for target 'dist/Debug/Cygwin-Windows/stockprogram_c__.exe' failed
make[2]: *** [dist/Debug/Cygwin-Windows/stockprogram_c__.exe] Error 1
make[2]: Leaving directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
nbproject/Makefile-Debug.mk:60: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/g/EDUCATION/University/Year 2/Year Courses/PROGRAMMING 2/Assignments/Assignment 2/COURSEWORK_100088688/StockProgram_C++'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 5s)
And just in case people need it, this is the class in question:
class Diode : public StockItem {
public:
Diode(char* componentT, char* code, int quantity, int price);
Diode(const Diode &D);
Diode& operator=(const Diode& D);
~Diode();
};
My question is why is this effecting the compilation? Any feedback (regardless of relevance) is greatly appreciated, thank you.
Error comes from undefined reference when linking.
You declare the functions, use them, but never implement the functions.
When linker link the object files and lib files, it would check the export symbols and import symbols then match them together.
Obvious, in your case, other class use your functions, treated as import symbols, but in class's object file, doesn't contain the function in export symbols table.
I have scoured google for a solution to fix this (including several posts here on c++ 11 features not working) and I can't find a solution. I have grown attached to netbeans in past year, using it for all my computer science courses. But it is slightly bothersome that some features of C++ are limited in my IDE, especially when they are features my professor is using to teach C++. When I use stoi() in any way I get an "Unable to resolve identifier" error. Is there a hot fix of sorts to get netbeans to acquire these features?
I've worked around it for my first programming assignment, but since I'm just now learning C++ I'd like to follow my professor's lead at the moment without doing anything extraneous.
I have tried the accepted solution here: How to use C++11 std::stoi with gcc?, and here: Netbeans C/C++ 7.2 -std=C++11 not recognized by gcc v4.6 or lower and I still get errors. And just as a disclaimer, to my knowledge I am using the listed includes involved here. So if anyone has a solution I'd appreciate it quite much.
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Zachary/Documents/NetBeansProjects/CS_240_HW01'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/cs_240_hw01.exe
make[2]: Entering directory '/cygdrive/c/Users/Zachary/Documents/NetBeansProjects/CS_240_HW01'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f "build/Debug/Cygwin_4.x-Windows/main.o.d"
g++ -std=c++0x -c -g -std=c++11 -MMD -MP -MF "build/Debug/Cygwin_4.x-Windows/main.o.d" -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
main.cpp: In function 'int main(int, char**)':
main.cpp:24:26: error: 'stoi' was not declared in this scope
int myint = stoi(test);
^
nbproject/Makefile-Debug.mk:84: recipe for target 'build/Debug/Cygwin_4.x-Windows/main.o' failed
make[2]: *** [build/Debug/Cygwin_4.x-Windows/main.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Zachary/Documents/NetBeansProjects/CS_240_HW01'
nbproject/Makefile-Debug.mk:62: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Zachary/Documents/NetBeansProjects/CS_240_HW01'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
EDIT: Added Build output
i have a litle problem using Netbeans 7.4 and Cygwin 4.x for compiling my C++ programms. I've done everything as in netbeans tutorial. I've installed gcc, gdb, g++ and make compilers. Everything is setup properly in Netbeans properties, every path. But i still get the same problem, i don't know what is this problem. I'm trying to compile Hello sample from Netbeans. Please help me. Here is the error log:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Dragosh/Documents/NetBeansProjects/Welcome_2'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/welcome_2.exe
make[2]: Entering directory '/cygdrive/c/Users/Dragosh/Documents/NetBeansProjects/Welcome_2'
mkdir -p build/Debug/Cygwin_4.x-Windows
g++ -c -g -o build/Debug/Cygwin_4.x-Windows/welcome.o welcome.cc
In file included from /usr/include/sys/reent.h:14:0,
from /usr/include/wchar.h:6,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/cwchar:44,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/iosfwd:40,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/ios:38,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/iostream:39,
from welcome.cc:31:
/usr/include/sys/_types.h:72:20: fatal error: stddef.h: No such file or directory
#include <stddef.h>
^
compilation terminated.
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/Cygwin_4.x-Windows/welcome.o' failed
make[2]: *** [build/Debug/Cygwin_4.x-Windows/welcome.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Dragosh/Documents/NetBeansProjects/Welcome_2'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Dragosh/Documents/NetBeansProjects/Welcome_2'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 467ms)
Got this issue with cygwin too, after last update to 2.830 (see setup.exe version). I am using 64 bit version. To verify that we have the same issue, try manualy compiling something supersimple with g++ usgin cygwin terminal.
I checked with:
$ echo -e "#include <iostream>\n int main() { return 0; }" | g++ -xc++ -
And got:
In file included from /usr/include/sys/reent.h:14:0,
from /usr/include/wchar.h:6,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/cwchar:44,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/iosfwd:40,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/ios:38,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/iostream:39,
from <stdin>:1:
/usr/include/sys/_types.h:72:20: fatal error: stddef.h: No such file or directory
#include <stddef.h>
^
compilation terminated.
I noticed that there are two folders of gcc here
C:\cygwin\lib\gcc\x86_64-pc-cygwin\4.8.1
C:\cygwin\lib\gcc\x86_64-pc-cygwin\4.8.2
and g++ --version gives 4.8.2
Running Cygwin's latest Setup.exe and looking for installed packets showed that versions mismatch for gcc-core and gcc-g++ :
gcc-core = 4.8.2-1
gcc-c++ = 4.8.1-3
I downgraded gcc-core to 4.8.1-3 and fixed the issue.
I'm a total c++ Newbie.
I'm trying to build windows aplications with Wx-Widgets under Net Beans.
So far so good. I have instaled everything, configured, build wx-widgets and attached it to the new project - with help of a good man here: Can't make wx-widget work with net-beans.
Now I try to build my first app:
#include <wx/string.h>
int main(int argc, char **argv)
{
wxPuts(wxT("A wxWidgets console application"));
}
and this is what I get:
I'm not sure if this is readable so I paste the errors:
g++ `C:\WXWIN\wx-config --cxxflags` -c -g -I../../../WXWIN/include `C:\WXWIN\wx-config --cxxflags` -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
/bin/sh.exe: C:WXWINwx-config: command not found
/bin/sh.exe: C:WXWINwx-config: command not found
In file included from ../../../WXWIN/include/wx/defs.h:21:0,
from ../../../WXWIN/include/wx/string.h:25,
from main.cpp:1:
../../../WXWIN/include/wx/platform.h:196:22: fatal error: wx/setup.h: No such file or directory
compilation terminated.
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `/c/xampp/htdocs/WxWwigets_tutorial'
make[1]: Leaving directory `/c/xampp/htdocs/WxWwigets_tutorial'
BUILD FAILED (exit value 2, total time: 859ms)
Please notice that I have set everything in linker and compiler like ordered: http://wiki.wxwidgets.org/Compiling_using_Netbeans
The error is right in front of you: "command not found". If you use /bin/sh, you must use Unix style paths, e.g. C:/WXWIN/wx-config instead of DOS paths with the backslashes.
I seriously advise you to get familiar with the environment you're using instead of just following the Wiki instructions without understanding them, otherwise your problems won't be over any time soon.