1

When I try to compile my CUDA program, I get the following errors:

b.o: In function `mul_wrapper':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0xcb): undefined reference to `cudaConfigureCall'
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0xe7): undefined reference to `cudaDeviceSynchronize'
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x144): undefined reference to `cudaFree'
b.o: In function `cudaError cudaMallocManaged<float>(float**, unsigned long, unsigned int)':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x18a): undefined reference to `cudaMallocManaged'
b.o: In function `__device_stub__Z3mulPf(float*)':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x1df): undefined reference to `cudaSetupArgument'
b.o: In function `cudaError cudaLaunch<char>(char*)':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x221): undefined reference to `cudaLaunch'
b.o: In function `__sti____cudaRegisterAll_36_tmpxft_00002a64_00000000_7_b_cpp1_ii__Z3mulPf()':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x243): undefined reference to `__cudaRegisterFatBinary'
b.o: In function `__nv_cudaEntityRegisterCallback(void**)':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x2f2): undefined reference to `__cudaRegisterFunction'
b.o: In function `__cudaUnregisterBinaryUtil()':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x31b): undefined reference to `__cudaUnregisterFatBinary'
collect2: error: ld returned 1 exit status
Makefile:3: recipe for target 'run' failed
make: *** [run] Error 1

My make file looks like this:

run: main.o b.o

    gcc -fPIC -L /usr/local/cuda/lib -lcudart -o run main.o b.o



main.o: main.c b.h

    gcc -fPIC -I /usr/local/cuda/include -c -o main.o main.c



b.o: b.cu b.h

    nvcc -Xcompiler -fPIC -ccbin clang-3.8 -c -o b.o b.cu

It seems like the problem has to do with the files "/usr/local/cuda/include" and "/usr/local/cuda/lib" not being found on my system. I am using Ubuntu 17.04 and have installed the CUDA toolkit with apt. I heard that installing CUDA toolkit with apt doesn't create the /usr/local/cuda/* files, so I tried to install it from the run file, but that faild to install.

UPDATE: I reinstalled CUDA toolkit and now I have the /usr/local/cuda/* directory, but the problem still persists.

  • _This question show research effort; it is useful and clear_. Well, your question is clear and seems to contain all the information needed to reproduce the problem. Though it does not show much research effort. What about searching the web for the error message? – hagello Aug 06 '17 at 19:28
  • 1
    try changing `/usr/local/cuda/lib` to `/usr/local/cuda/lib64` Also you may have a c/c++ linking issue here. Is there any reason you can't rename your `main.c` to `main.cpp` (and modify your Makefile accordingly)? – Robert Crovella Aug 06 '17 at 19:50
  • 5
    Specify the shared library *after* the object files which rely on it, not before. Unix style linking commands are parsed left to right and the library will be excluded because there is no dependency when the library is reached – talonmies Aug 06 '17 at 20:12
  • @talonmies This is my first time using linking commands and object files, so I'm not sure how to find what object files rely on what libraries. – SupaKoopaTroopa64 Aug 06 '17 at 20:24
  • You don't have to know anything about any of that. Just do exactly what I said. Libraries after the objects you have compiled and are linking, not before – talonmies Aug 06 '17 at 20:27
  • So change "gcc -fPIC -L /usr/local/cuda/lib -lcudart -o run main.o b.o" to "gcc -fPIC -lcudart -o run main.o b.o -L /usr/local/cuda/lib"? Sorry if I'm not understanding. – SupaKoopaTroopa64 Aug 06 '17 at 20:40
  • 2
    Do this: `gcc -fPIC -L/usr/local/cuda/lib -o run main.o b.o -lcudart` And you may need to change `lib` to `lib64`, and you may also need to change `main.c` to `main.cpp` (with corresponding changes through your Makefile for the main.c to main.cpp change) – Robert Crovella Aug 06 '17 at 21:40
  • @Robert Crovella That did it! – SupaKoopaTroopa64 Aug 06 '17 at 21:44
  • 1
    I'm not sure which "That" you are referring to. Anyway, if you want to explain the changes you made in an answer (you can answer your own question) it may be useful for future readers. – Robert Crovella Aug 06 '17 at 21:57
  • @Robert Crovella By "that" I'm referring to moving the -lcudart to the end of the command. And I will make an answer so no one has to face the dreaded "Never mind, it works now". – SupaKoopaTroopa64 Aug 06 '17 at 23:19

0 Answers0