Search code examples
configurationcompilationlibrariesldraylib

ld cannot find a library that exists and is configured properly


I'm running Ubuntu 22.04.2 LTS and I've been trying to compile and manually install raylib, but when I compile with gcc and try to link against the library I get the following error:

/usr/bin/ld: cannot find -lraylib: No such file or directory

I've installed the shared libraries (following the directions here) into ~/compiled/bin/raylib/lib. I then configured ld with ldconfig to find the libraries by adding a raylib.conf file in /etc/lib.so.conf.d/ which simply contains this:

/home/user_name/compiled/bin/raylib/lib/

When I run ldconfig -p | grep raylib I get the following output:

libraylib.so.450 (libc6,x86-64) => /home/user_name/compiled/bin/raylib/lib/libraylib.so.450
libraylib.so (libc6,x86-64) => /home/user_name/compiled/bin/raylib/lib/libraylib.so

This is the output of ll on the directory which contains the libraries:

total 2084
drwxr-xr-x 2 root root    4096 Jul 16 12:38 ./
drwxr-xr-x 4 root root    4096 Jul 15 17:21 ../
lrwxrwxrwx 1 root root      16 Jul 16 12:38 libraylib.so -> libraylib.so.450*
-rwxr-xr-x 1 root root 2121984 Jul 15 17:21 libraylib.so.4.5.0*
lrwxrwxrwx 1 root root      18 Jul 15 17:21 libraylib.so.450 -> libraylib.so.4.5.0*

This follows the structure of every other library I've installed with the only difference being the asterisks which mark the symlink targets and the actual library as executable? I've tried renaming the files and the symlinks targets, but this doesn't change anything. Prepending the path of the libraries to LD_LIBRARY_PATH doesn't work either.


Solution

  • So, it looks like you can't configure the default search path of the linker (ld, which looks for libraries at linking time), and ldconfig only modifies the search path of the loader (ld.so which looks for the libraries at run time). The only way to get around this is to use the -L flag on gcc and specify the path. This is kind of frustrating tbh. I don't see any reason why the default search path for the linker can't be overridden.