So now, I have also a lib "cuLib " that I called in both cuSource.cu and cppSource.cpp !
To compile them. I do :
And there I get a lots of “undefined references” to cuda stuff! Of course if I use nvcc instead of g++ for the last command it will work but I need g++ to create the final program and not nvcc !
You try to link your object-files together, but the linker (ld is called from gcc/g++) does not know that you are using a library. So you need to specify the library with -l. If your library’s name is “libmyLibrary.so”, set the linker option “-lmyLibrary”. If you’re using the CUDA runtime API, always set “-lcudart” when linking.
In that case, you are using the runtime API. Imagine the following example:
You have 3 source and 2 header files:
main.cpp
helloWorld.h
helloWorld.cpp
myFirstCudaKernel.cu // with some cuda code
myFirstCudaKernel.cuh
The header files are normally included in one of the source files, so you don’t need to pass them explicitly to the compiler. The .cu files use the CUDA runtime API (all cuda*() functions) and therefore you need to link against this library. Now you type:
Ok thanks a lot for all these explanations ! It doesn’t work with the -lcudart but after some researches in the nvcc guide I found more details about it and it works when I enter the path of the library ( /usr/local/cuda/lib/libcudart.so ) ! That’s strange because my LD_LIBRARY_PATH contains /usr/loca/cuda/lib/ so I’m not supposed to have to write the whole path but the most important is that it’s now working ! Thanks again for your help !