The cross linker error when cross compiling aarch64-linux-gnu/bin/ld: cannot find -lcuda

Environment: ubuntu 20.04
cross compiler: gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu

I am doing cross compile on x86 for aarch64. I clone the Xavier and mounted clone.img.raw on jetson folder
so the xavier filesystem is in jetson folder

and then, I use cmake to build the code
the cmake configuration is like below

# the name of the target operating system
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_HOST_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(CMAKE_C_COMPILER  home/username/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER home/username/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=/home/username/jetson" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --sysroot=/home/username/jetson " CACHE INTERNAL "" FORCE)

set(CMAKE_FIND_ROOT_PATH /home/username/jetson 
                         home/username/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

I use find_package to find opencv and when I cmake and make the code, the output is

[100%] Linking CXX executable testing
/home/username/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.3.1/../../../../aarch64-linux-gnu/bin/ld: cannot find -lcuda
collect2: error: ld returned 1 exit status

-lcuda is libcuda.so and this shared library exists in jetson folder(/home/username/jetson/usr/lib/aarch64-linux-gnu).
I deduce the cross linker ld want to find libcuda.so but the path is not included in ld’s SEARCH_DIR
I check SEARCH_DIR of ld

 $ ./ld --verbose | grep SEARCH_DIR | tr -s ' ;' \\012 
SEARCH_DIR("=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu/aarch64-linux-gnu/lib64") SEARCH_DIR("=/usr/local/lib64") 
SEARCH_DIR("=/lib64") 
SEARCH_DIR("=/usr/lib64") 
SEARCH_DIR("=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu/aarch64-linux-gnu/lib") SEARCH_DIR("=/usr/local/lib") 
SEARCH_DIR("=/lib") 
SEARCH_DIR("=/usr/lib")

there is no path correspond to the path of libcuda.so
How let ld linker to find the library it needs? thanks.

Hi,
Here are the setting on Jetson platforms:

nvidia-desktop:~$ echo $LD_LIBRARY_PATH
/usr/local/cuda-10.2/lib64:
nvidia-desktop:~$ echo $PATH
/home/nvidia/.local/bin:/usr/local/cuda-10.2/bin:/usr/local/sbin:/usr/local/bin:
/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
nvidia-desktop:~$ ll /usr/local/cuda
lrwxrwxrwx 1 root root 22 十二 15 10:11 /usr/local/cuda -> /etc/alternatives/cuda/
nvidia-desktop:~$ ll /etc/alternatives/cuda
lrwxrwxrwx 1 root root 20 十二  2 13:35 /etc/alternatives/cuda -> /usr/local/cuda-10.2/

Please apply the same on the host PC and try again.

Hi,
I apply these commands on the x86 host but I assign the direction to folder mounted by clone.img.raw
called jetson(clone filesystem from Xavier)
therefore, the result like below

$ echo $LD_LIBRARY_PATH
/home/username/jetson/usr/local/cuda-10.2/lib64:
$ echo $PATH
/home/username/jetson/usr/local/cuda-10.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ ll jetson/usr/local/cuda
lrwxrwxrwx 1 root root 22  3月 15  2022 **jetson/usr/local/cuda -> /etc/alternatives/cuda**
$ ll jetson/etc/alternatives/cuda
lrwxrwxrwx 1 root root 20  3月 15  2022 **jetson/etc/alternatives/cuda -> /usr/local/cuda-10.2/**

and I found /jetson/usr/local/cuda is a broken link
jetson/etc/alternatives/cuda is linked to /usr/local/cuda-10.2(on x86 host)

I hope cross compiler and its linker can use aarch64 cuda directly from the jetson folder mounted by clone.img.raw
and will it be a problem and how to solve it?

The symbolic links might be wrong after mounting a clone somewhere else. It just depends. If the symbolic link is a relative path, then it is usually correct; if the symbolic link is an absolute path, then the clone mount is likely wrong. You could convert the symbolic link from absolute to relative if this is the issue.

To see the content of what the link itself points at use “ls -l” on the full path. Example, if the mount point is “~/jetson”:

ls -l ~/jetson/usr/local/cuda
ls -l ~/jetson/etc/alternatives/cuda

Let’s pretend that you now have this (adjust for your case):
~/jetson/usr/local/cuda -> /etc/alternatives/cuda/

If you cd to “~/jetson/usr/local/, then you could convert this to a relative path if the absolute path is wrong:

cd ~/jetson/usr/local
# Method one, absolute path, but adjusted:
sudo ln -sf ./cuda ~/jetson/etc/alternatives/cuda
# Now verify it points to the next location:
ls -l ./cuda

# BETTER choice, convert to relative path so any mount point works:
cd ~/jetson/usr/local
sudo ln -sf ./cuda ../../etc/alternatives/cuda
# Verify:
ls -l ./cuda

Each “../” implies go up to one parent directory. From “~/jetson/usr/local”, the “../” is the same as “~/jetson/usr”; then “../../” is “~/jetson”, and “../../etc/alternatives” is “~/jetson/etc/alternatives”, but the relative path method will remain correct no matter where you mount the clone image.

If “~/jetson/alternatives/cuda” also points to an absolute path, then you’d do the same thing there until all relative paths point to actual content.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.