g++ : some linking problem


I try to sort a vector of long thanks to CUDA. I have for that two files : a .cpp file creates and instantiates the vector, transforms it in an array (it’s to make some comparison with the std::sort function) and call a a C function contained the .cu file. The C function calls the function that sorts the array on the GPU.

I made a makefile to compile all that :


all : sorting_aos_vs_soa

test_vector : test_vector.o sorting_aos_vs_soa.cuo

g++ test_vector.o sorting_aos_vs_soa.cuo -o test_vector -lcuda -L/usr/local/cuda/lib -L /opt/NVIDIA_GPU_Computing_SDK/shared/lib/linux/ -I /usr/include/cuda -I /usr/local/cuda/include

test_vector.o : test_vector.cpp

g++ -c test_vector.cpp -o test_vector.o -lcuda -I /usr/include/cuda -I /usr/local/cuda/include

sorting_aos_vs_soa: sorting_aos_vs_soa.cuo

gcc sorting_aos_vs_soa.cuo -o sorting_aos_vs_soa -lcuda -I /usr/include/cuda -I /usr/local/cuda/include

sorting_aos_vs_soa.cuo: sorting_aos_vs_soa.cu

nvcc -c sorting_aos_vs_soa.cu -o sorting_aos_vs_soa.cuo -l cuda -I /usr/include/cuda -I /usr/local/cuda/include  -I /usr/local/cuda/lib/ -L /usr/local/cuda/lib

test_vector.cpp : sorting_aos_vs_soa.h


There are two targets : all and test_vector. The target “all” compiles with no problem and I can execute sorting_aos_vs_soa (it sorts an arrray). When I want to compile “test_vector”, it has some errors when it links the object files. The errors are all like :

[codebox]sorting_aos_vs_soa.cuo: In function `__sti____cudaRegisterAll_53_tmpxft_00003c4a_00000000_4_s


tmpxft_00003c4a_00000000-10_sorting_aos_vs_soa.ii:(.text+0xbeed): undefined reference to `__cudaRegisterShared’

tmpxft_00003c4a_00000000-10_sorting_aos_vs_soa.ii:(.text+0xbefe): undefined reference to `__cudaRegisterShared’

tmpxft_00003c4a_00000000-10_sorting_aos_vs_soa.ii:(.text+0xbf0f): undefined reference to `__cudaRegisterShared’

tmpxft_00003c4a_00000000-10_sorting_aos_vs_soa.ii:(.text+0xbf20): undefined reference to `__cudaRegisterShared’

tmpxft_00003c4a_00000000-10_sorting_aos_vs_soa.ii:(.text+0xbf31): undefined reference to `__cudaRegisterShared’[/codebox]

I’ve also executed these commands :

export LD_LIBRARY_PATH=/home_nfs/fremals/local/starpu/lib/:/usr/local/cuda/lib

export C_INCLUDE_PATH=/home_nfs/fremals/local/starpu/include/:/usr/include/cuda:/usr/local/cuda/include:/home_nfs/fremals/local/myLib:/usr/local/cuda/lib/

I don’t know what to do else so it can compile with no errors. Can someone help me please ?

Thank you !!

Try adding -lcudart to the linkline.


Try adding -lcudart to the linkline.



I already tried, but it can’t find -lcudart. I’ve linked the file containing the libcudart.so library in the makefile. But as the the “all” target compiles, I don’t think it is necessary to have lcudart for this application.

In trying to use -lcudart, I saw that error :
/usr/bin/ld: skipping incompatible /usr/local/cuda/lib/libcudart.so when searching for -lcudart
/usr/bin/ld: cannot find -lcudart

Maybe it’s my main problem, I’ll search how to solve that.

You’re probably running a 64-bit OS, in which case you should use -L/usr/local/cuda/lib64 instead of -L/usr/local/cuda/lib


Hi Elliole,

What about just using StarPU’s pkg-config to do this ? (so that you don’t have to decide by hand where is CUDA)

In your .bashrc (for instance)
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/home_nfs/fremals/local/starpu/lib/pkgconfig/

and then add this in your Makefile the following lines
LDFLAGS+=$$(pkg-config --libs libstarpu)
CFLAGS+=$$(pkg-config --cflags libstarpu)

I would also try the following:
NVCFLAGS+=$$(pkg-config --cflags libstarpu)

And then change “nvcc -c” into “nvcc $(NVCFLAGS) -c”.

Does that help a little ?



Sorry for the late reaction. The solution of Nico works !! It compiles with no problem now.

I’ve some urgent work, so I don’t have time to test your solution, gonnet, but I think I’m going to adopt it later.

Thank you both !!