Pregunta

These commands were generated procedurally by a Makefile that I essentially copied from NVIDIA's tutorial pages; it's over 100 lines long and will post it if you think it's necessary, but these commands are sufficient to reproduce the errors.

g++ -m64  -I/usr/local/cuda/include -I. -I.. -I../../common/inc -I/usr/local/cuda/lib64 -o shallowwater.o -c shallowwater.cpp

/usr/local/cuda/bin/nvcc -m64  -gencode arch=compute_10,code=sm_10 -gencode arch=compute_20,code=sm_20 -I/usr/local/cuda/include -I. -I.. -I../../common/inc -I/usr/local/cuda/lib64 -o shallowwatercudamain.o -c shallowwatercudamain.cu

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -lcudart 

The first two work; there is no compile error for either of the two source files, but when the third command is run, I get the following error:

shallowwatercudamain.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00004e70_00000000-4_shallowwatercudamain.compute_20.cudafe1.cpp:(.text+0x36): undefined reference to `__cudaUnregisterFatBinary'
shallowwatercudamain.o: In function `__sti____cudaRegisterAll_66_tmpxft_00004e70_00000000_6_shallowwatercudamain_compute_20_cpp1_ii_runIt()':
tmpxft_00004e70_00000000-4_shallowwatercudamain.compute_20.cudafe1.cpp:(.text+0x46): undefined reference to `__cudaRegisterFatBinary'
collect2: ld returned 1 exit status
make: *** [shallowwater] Error 1

Here is some relevant system information:

[foo@bar code]$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2012 NVIDIA Corporation
Built on Thu_Apr__5_00:24:31_PDT_2012
Cuda compilation tools, release 4.2, V0.2.1221
[foo@bar code]$ uname -a
Linux intel19 2.6.32-71.el6.x86_64 #1 SMP Wed Sep 1 01:33:01 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

I found someone with a similar error here, seen here: /usr/bin/ld: cannot find -lcudart I'm embarrassed to say I found this, made the same change except for g++ instead of gfortran, and it worked. Afterwards, I tried it again and it did not work. I get the same error with:

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -L/usr/local/cuda/lib64
¿Fue útil?

Solución

This command does not look right to me:

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -lcudart 

And this command does not look right to me:

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -L/usr/local/cuda/lib64

This command looks right to me:

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L/usr/local/cuda/lib64 -lcudart

You need to tell g++ where to look for the cudart library, that is what the -L/usr/local/cuda/lib64 switch is for (so it needs a path, you cannot just use -L by itself) and you need to tell g++ the name of the library to use, that is what the -lcudart is for.

Otros consejos

I realized you didnt put "-lcudart" in your last line. Did you link to cudart when you were doing actual compilation ?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top