Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc - /usr/bin/ld error: cannot find <library> in /usr/local/lib though ldconfig list it, and path added to ld.so.conf

Tags:

c++

linux

gcc

ld

I try to compile a C++ code, using a library I've also compiled manually and installed in /usr/local/lib

The compilation of the software fails at the linking step:

 /usr/bin/ld: error: cannot find -lcppdb

it seems that g++ does not search by default in /usr/local/lib , same for clang++

 g++ -print-search-dirs # does not show /usr/local/lib

however the fact is /usr/local/lib is in my /etc/ld.so.conf and I did run ldconfig as root, and actually running ldconfig -p | grep cppdb shows me

libcppdb_sqlite3.so.0 (libc6) => /usr/local/lib/libcppdb_sqlite3.so.0
libcppdb_sqlite3.so (libc6) => /usr/local/lib/libcppdb_sqlite3.so
libcppdb.so.0 (libc6) => /usr/local/lib/libcppdb.so.0
libcppdb.so (libc6) => /usr/local/lib/libcppdb.so

adding the option -L/usr/local/lib of course solve the problem, but the goal is to use configuration files

like image 774
allan.simon Avatar asked Nov 02 '13 01:11

allan.simon


2 Answers

ld, the linker, does not use external configuration files for that. ldconfig is for the loader, ld.so. Create a makefile if you want to set values for the linker somewhere.

like image 168
Ignacio Vazquez-Abrams Avatar answered Oct 05 '22 23:10

Ignacio Vazquez-Abrams


Specifying -L switches in your makefile is a common way to deal with this problem, but you can actually make system-wide changes by modifying the default GCC spec file, which can be used to specify additional options to be passed to the compiler, linker, etc. I've done this in the past to address your specific problem, but it was a long time ago, so I can't give you a specific example, unfortunately.

like image 35
jjlin Avatar answered Oct 05 '22 23:10

jjlin