Get rid of "gcc - /usr/bin/ld: warning lib not found" Get rid of "gcc - /usr/bin/ld: warning lib not found" linux linux

Get rid of "gcc - /usr/bin/ld: warning lib not found"


You need to add the dynamic library equivalent of -L:

-Wl,-rpath-link,/path/to/lib

This will cause the linker to look for shared libraries in non-standard places, but only for the purpose of verifying the link is correct.

If you want the program to find the library at that location at run-time, then there's a similar option to do that:

-Wl,-rpath,/path/to/lib

But, if your program runs fine without this then you don't need it.


Make sure the paths to the needed libraries are known to the runtime linker. This is done by adding a file in /etc/ld.so.conf.d/ with the needed path. For example, /etc/ld.so.conf.d/foo with the following contents:

/usr/local/lib/foo/

If you have a very old Linux version, /etc/ld.so.conf.d/ might not be supported, in which case you might have to add the paths directly into the /etc/ld.so.conf file.

After you've done that, you need to update the linker's database by executing the "ldconfig" command.


I know this is old, but here's a better fix:

The root cause:

The problem actually happens when LD invoked by GCC starts resolvinglibrary dependencies. Both GCC and LD are aware of the sysrootcontaining libraries, however LD may be missing one criticalcomponent: the /etc/ld.so.conf file. Here’s an exampleld.so.conf filefrom a Raspberry PI system:

include /etc/ld.so.conf.d/*.conf

The /etc/ld.so.conf.d directory contains the following files:

00-vmcs.conf:/opt/vc/lib

arm-linux-gnueabihf.conf:

/lib/arm-linux-gnueabihf /usr/lib/arm-linux-gnueabihf

libc.conf:

/usr/local/lib

The universal solution

 

The problem can be easily solved by copying the LD configuration filesto a location where the cross-toolchain’s LD can find them. There’sone pitfall however: if your cross-toolchain was built with MinGW(most are), it probably did not have access to the glob() function soit won’t be able to parse a wildcard-enabled include statementlike *.conf. The workaround here is to just manually combine thecontents of all .conf files from /etc/ld.so.conf.d and paste theminto /etc/ld.so.conf

*/opt/vc/lib

/lib/arm-linux-gnueabihf

/usr/lib/arm-linux-gnueabihf

/usr/local/lib*

Once you create the ld.so.conf file in the correct folder, yourtoolchain will be able to resolve all shared library referencesautomatically and you won’t see that error message again!