Link error to use CUDA static library ? Link error to use CUDA static library ??

I am confused to use a static library file *.a that compiled from “nvcc” command.

I put the *.cu and *.h in the path : /home/fbg/NVIDIA_CUDA_SDK/projects/interleave_7/

, then I used the below command to produce a *.a file.

nvcc -o libCUDA_interleave_7.a CUDA_interleave_7.cu -L/home/fbg/NVIDIA_CUDA_SDK/common/lib/linux/ -L/home/fbg/NVIDIA_CUDA_SDK/lib -lcudpp -lcutil -lib --compiler-options ‘-fPIC’

It seems ok to get a *.a file, but it cause some problem when I add this *.a into other project and make the execute file.

I don’t know what’s wrong with my steps, or other notes I ignore??? :wacko:

//-------------- error message -----------------------------------------------------------

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x6e22): undefined reference to `__cudaRegisterFatBinary’

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x6e94): undefined reference to `__cudaRegisterFunction’

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x6ed6): undefined reference to `__cudaRegisterTexture’

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o): In function `_device_stub__Z20GPU_interleave_7viewiiiiPhS’:

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x6f59): undefined reference to `cudaSetupArgument’

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x6f81): undefined reference to `cudaSetupArgument’

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x6fa9): undefined reference to `cudaSetupArgument’

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o):tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x701f): more undefined references to `cudaSetupArgument’ follow

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o): In function `__ftexfetch’:

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x7be2): undefined reference to `__cudaTextureFetch’

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o): In function `__utexfetch’:

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x7c22): undefined reference to `__cudaTextureFetch’

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o): In function `__itexfetch’:

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x7c62): undefined reference to `__cudaTextureFetch’

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o): In function

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x7ce2): undefined reference to `__cudaTextureFetch’

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o):tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0x7d22): more undefined references to `__cudaTextureFetch’ follow

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o): In function `__cudaUnregisterBinaryUtil’:

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0xa5f0): undefined reference to `__cudaUnregisterFatBinary’

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o): In function `CUDA_7view_interleave_dele(unsigned char**, unsigned char**)’:

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0xa61c): undefined reference to `cudaFree’

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0xa63b): undefined reference to `cudaFree’

/home/fbg/work/MyProject/…/libraries/i686-linux/lib_release_client/libCUDA_interleave_7.a(tmpxft_00003d2e_00000000-12_CUDA_interleave_7.o): In function `CUDA_7view_interleave_proc(int, int, int, int, int, int, unsigned char*, unsigned char*, unsigned char*, unsigned char*, unsigned char*, unsigned char*, unsigned char*, unsigned char*, unsigned char*, unsigned char*)’:

tmpxft_00003d2e_00000000-11_CUDA_interleave_7.ii:(.text+0xa6de): undefined reference to `cudaMemcpy’

I had a similar problem earlier but seemed to have resolved it using the following.

I made the .a file using

nvcc -lib CUDA_interleave_7.cu -o libCUDA_interleave_7.a

to link with your other project

nvcc main.cpp -L("location of your libCUDA_interleave.a) -lCUDA_interleave_7 -L /usr/local/cuda/lib -lcudart -lcuda -o output

i got that error when I didn’t link to -lcudart. hope that helps.