Linking to c++ object

I am trying to link my cuda object to my main program. The regular cpp files were compiled to .o object, and the cuda stuff to the .co object.

What am I missing? This is the linker command, and corresponding output.

I used essentially the same type of command before to create an archive which I was able to link to a different executable, but this seems to be giving me a problem.

Thanks

g++  -o YamaguchiGPU YamaguchiMain.o YamaguchiDecomp.o cuYamaguchi.co -L/usr/lib64/ ../../lib/IDT.a ../../lib/Linux/libxerces-c.a ../../lib/Linux/libfftw3f.a -lcurl -lidn -ldl -lssl -lm -lpthread -lcuda -L/usr/local/cuda/lib64/libcudart.so -L/usr/lib64/libcuda.so 

cuYamaguchi.co: In function `__sti____cudaRegisterAll_46_tmpxft_000032a2_00000000_4_cuYamaguchi_cpp1_ii_init_gpu()':

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x1b4): undefined reference to `__cudaRegisterFatBinary'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x20f): undefined reference to `__cudaRegisterFunction'

cuYamaguchi.co: In function `__cudaUnregisterBinaryUtil()':

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x23c): undefined reference to `__cudaUnregisterFatBinary'

cuYamaguchi.co: In function `__device_stub__Z22yamaguchi_solve_kerneliiiP6float2S0_S0_Pf(int, int, int, float2*, float2*, float2*, float*)':

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x278): undefined reference to `cudaSetupArgument'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x29e): undefined reference to `cudaSetupArgument'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x2c4): undefined reference to `cudaSetupArgument'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x2ea): undefined reference to `cudaSetupArgument'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x30c): undefined reference to `cudaSetupArgument'

cuYamaguchi.co:tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x32e): more undefined references to `cudaSetupArgument' follow

cuYamaguchi.co: In function `yama_wrapper':

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x1758): undefined reference to `cudaConfigureCall'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x17a9): undefined reference to `cudaFreeHost'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x17b5): undefined reference to `cudaFreeHost'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x17c1): undefined reference to `cudaFreeHost'

cuYamaguchi.co: In function `init_gpu':

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x1908): undefined reference to `cudaHostAlloc'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x192c): undefined reference to `cudaHostAlloc'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x193f): undefined reference to `cudaHostAlloc'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x195c): undefined reference to `cudaHostAlloc'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x1983): undefined reference to `cudaHostGetDevicePointer'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x19aa): undefined reference to `cudaHostGetDevicePointer'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x19c0): undefined reference to `cudaHostGetDevicePointer'

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x19d6): undefined reference to `cudaHostGetDevicePointer'

cuYamaguchi.co: In function `cudaError cudaLaunch<char>(char*)':

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x11): undefined reference to `cudaLaunch'

cuYamaguchi.co: In function `__cudaSafeCall(cudaError, char const*, int)':

tmpxft_000032a2_00000000-1_cuYamaguchi.cudafe1.cpp:(.text._Z14__cudaSafeCall9cudaErrorPKci[__cudaSafeCall(cudaError, char const*, int)]+0x1c): undefined reference to `cudaGetErrorString'

collect2: ld returned 1 exit status

You haven’t linked the cuda runtime library (libcudart.so).

isnt that what is going on with this part of the linker command:

-L/usr/lib64/ …/…/lib/IDT.a …/…/lib/Linux/libxerces-c.a …/…/lib/Linux/libfftw3f.a -lcurl -lidn -ldl -lssl -lm -lpthread -lcuda -L/usr/local/cuda/lib64/libcudart.so

No. -L is only used used to specify paths for the linker to search. -l specifies which shared libraries will be linked. You haven’t linked libcudart anywhere in that command.

It is weird, this works when I use nvcc:

nvcc -I …/readers/ -I…/writers -I…/common/ -I /home/dcole/software/xerces-c-3.1.1/src -I /home/dcole/NVIDIA_GPU_Computing_SDK/C/common/inc/ -I /usr/local/cuda/include -o YamaguchiGPU YamaguchiMain.o YamaguchiDecomp.o cuYamaguchi.o -L/usr/lib64/ …/…/lib/IDT.a …/…/lib/Linux/libxerces-c.a …/…/lib/Linux/libfftw3f.a -lcurl -lidn -ldl -lssl -lm -lpthread -lcuda -L/usr/local/cuda/lib64/libcudart.so -lgomp

But I had to take out the -fPIC option and -fopenmp that I use with g++. and add in the -lgomp library to get openmp support.

Seems like there has to be a better way than that - what am I doing wrong?

Nvcc silently links the CUDA libraries without needing any explicit library specification. I think you need to read some gcc documentation before you try going any further.

Ah, your explanation of -l and -L cleared it up for me. I took out the absolute path in the -L and just made it point to the lib54 directory, then included -lcudart, and it worked. Thanks for the clarification