17

I am newbie to Ubuntu and using Ubuntu 14.04 64-bit. I want to make a project that uses cuda and opencv I got the following error when running cmake . && make

Linking CXX executable ground_estimation
/usr/bin/ld: cannot find -lcudart
collect2: error: ld returned 1 exit status
make[2]: *** [ground_estimation] Error 1
make[1]: *** [CMakeFiles/ground_estimation.dir/all] Error 2
make: *** [all] Error 2

This is the output of ld -lcudart --verbose

attempt to open /usr/x86_64-linux-gnu/lib64/libcudart.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libcudart.a failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libcudart.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libcudart.a failed
attempt to open //usr/local/lib64/libcudart.so failed
attempt to open //usr/local/lib64/libcudart.a failed
attempt to open //lib/x86_64-linux-gnu/libcudart.so failed
attempt to open //lib/x86_64-linux-gnu/libcudart.a failed
attempt to open //lib64/libcudart.so failed
attempt to open //lib64/libcudart.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libcudart.so failed
attempt to open //usr/lib/x86_64-linux-gnu/libcudart.a failed
attempt to open //usr/lib64/libcudart.so failed
attempt to open //usr/lib64/libcudart.a failed
attempt to open //usr/local/lib/libcudart.so failed
attempt to open //usr/local/lib/libcudart.a failed
attempt to open //lib/libcudart.so failed
attempt to open //lib/libcudart.a failed
attempt to open //usr/lib/libcudart.so failed
attempt to open //usr/lib/libcudart.a failed

libcudart exist in /usr/local/cuda/lib64 and I also added to Library Path:

echo $LD_LIBRARY_PATH
/usr/lib/nvidia-current:/usr/local/cuda/lib64:/usr/local/cuda/lib:

This is the output of ls /usr/local/cuda/lib64:

libcublas_device.a   libcufftw.so.6.0.37    libnppi.so.6.0
libcublas.so         libcuinj64.so          libnppi.so.6.0.37
libcublas.so.6.0     libcuinj64.so.6.0      libnpps.so
libcublas.so.6.0.37  libcuinj64.so.6.0.37   libnpps.so.6.0
libcudadevrt.a       libcurand.so           libnpps.so.6.0.37
libcudart.so         libcurand.so.6.0       libnvblas.so
libcudart.so.6.0     libcurand.so.6.0.37    libnvblas.so.6.0
libcudart.so.6.0.37  libcusparse.so         libnvblas.so.6.0.37
libcudart_static.a   libcusparse.so.6.0     libnvToolsExt.so
libcufft.so          libcusparse.so.6.0.37  libnvToolsExt.so.1
libcufft.so.6.0      libnppc.so             libnvToolsExt.so.1.0.0
libcufft.so.6.0.37   libnppc.so.6.0         libOpenCL.so
libcufftw.so         libnppc.so.6.0.37      libOpenCL.so.1
libcufftw.so.6.0     libnppi.so

What should I do that ld search in /usr/local/cuda/lib64 path to find libcudart?

2
  • can you please ls /usr/local/cuda/lib64?
    – AlexGreg
    Aug 12, 2014 at 9:15
  • The same question happened to me too. Reference from the article: [Debian compiling OpenCV examples with IPP: /usr/bin/ld: cannot find -llibsvml.so collect2: error: ld returned 1 exit status.][1] [1]: stackoverflow.com/questions/24234961/… Nov 15, 2014 at 2:55

5 Answers 5

25

Make a symbolic link to libcuda where ld is searching it.

sudo ln -s /usr/local/cuda/lib64/libcudart.so /usr/lib/libcudart.so
1
  • Is there a way to symlink the whole /lib folder without symlinking every individual file?
    – WolfLink
    Apr 26, 2022 at 0:54
15

LD_LIBRARY_PATH is used to modify the behaviour of the ldconfig and related tools when looking for the libraries, at execution time.

The ld linker tool doesn't use this variable. If you want to use a library located in a non-standard directory, you have to use the -L parameter of the command, like this :

ld -lcuda -L/usr/local/cuda/lib64

If you have downloaded and existing project and doesn't know how to modify the existing Makefile(s) without breaking the whole compilation, you can run make the following way :

export LDFLAGS=-L/usr/local/cuda/lib64
make

The variable LDFLAGS (which may be also defined into the Makefile), is used to pass specific arguments to the linker (ld) when launched by the compilation intructions.

3
  • 1
    I got ld: warning: cannot find entry symbol _start; not setting start address when run ld -lcuda -L/usr/local/cuda/lib64
    – Arash
    Aug 12, 2014 at 9:52
  • @Arash: did you install the version of libcuda requested by the porject you try to compile ?
    – Benoit
    Aug 12, 2014 at 11:34
  • same problem as @Arash and yes I have the correct version of libcuda
    – Mohsin
    Feb 12, 2019 at 6:38
2

You can make links instead of adding the paths:

ln -s /usr/local/cuda/lib64/libcudart.so /usr/local/lib/
ln -s /usr/local/cuda/lib64/libcudart.a /usr/local/lib/
1
  • i do not have /usr/local/lib64/ ,i have /usr/local/lib/
    – Arash
    Aug 12, 2014 at 9:46
1

I fixed this! Go to your makefile and change

/usr/local/cuda/

to

/usr/local/cuda-7.0

(if that's what you got)

It worked for me

0

Solved

git clone https://github.com/inducer/pycuda.git
cd pycuda
sudo configure --cuda-root=/usr/lib/cuda-10.1

sudo ln -s /usr/lib/cuda-10.1/targets/x86_64-linux/include src/cpp/

OR copy all header files from /usr/lib/cuda-10.1/targets/x86_64-linux/include to /src/cpp/

It worked for me on Pop-OS 19.10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .