NVCC -g -G question

I have a question regarding nvcc, specifically nvcc -g -G (to use with cuda-gdb).

System Info:

I’m on redhat linux, I have set up Eclipse CDT to work with CUDA.

When I compile from eclipse, the build goes as:

make all
Building file: …/log.cu
Invoking: CUDA NVCC Compiler
nvcc -c -o “cu_log.o” “…/log.cu” &&
echo -n ‘cu_log.d’ ./ > ‘cu_log.d’ &&
nvcc -M “…/log.cu” >> ‘cu_log.d’

Finished building: …/log.cu

Building target: CudaParameters
Invoking: C++ Linker
nvcc -L/usr/local/cuda/lib64 -Xlinker -rpath -Xlinker /usr/local/cuda/lib64 -o “CudaParameters” ./InputArray.o ./cu_log.o -lcudart
Finished building target: CudaParameters

Once this is finished I can run the project.

But if I try to debug from a terminal with NVCC -g -G: this is what I get:

$ nvcc -g -G log.cu

/tmp/tmpxft_00003f42_00000000-13_log.o: In function main': workspace/CudaParameters/log.cu:40: undefined reference to InputArray::InitiateArray(std::basic_fstream<char, std::char_traits >&)’
collect2: ld returned 1 exit status

I have successfully debugged the file before (compiled with NVCC -g -G). The difference is that I added a c++ file to the project. Now NVCC -g -G doesn’t work for me.

Are there other flags I should be putting in?


I may be wrong, but I think the problem is that the linker cannot find the object code for that array class. You should include the -c argument followed by the files that contain the code, or just list the object files that have already been compiled (I haven’t been in unix land for a while so I’m a little rusty).

If I recall correctly, nvcc compiles all the code by either calling gcc or running it’s own compiler on the cuda code. Then it invokes ld to link the object code into an executable. You aren’t telling the linker where to find the code it needs.

Again, I could be wrong. Visual Studio keeps me from having to think about it.