简体   繁体   中英

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

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 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

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.

在makefile中指定-L开关是解决此问题的常用方法,但您实际上可以通过修改默认GCC 规范文件来进行系统范围的更改,该文件可用于指定要传递给编译器,链接器的其他选项等我过去这样做是为了解决你的具体问题,但很久以前,所以我不能给你一个具体的例子。

  1. You can use linker script, and add '/usr/local/lib' to search_dir. see this Linker_Scripts to get more details.

  2. add /usr/local/lib to GCC_EXEC_PREFIX shell environment, and try it again. more details search print-search-dirs in "man" of g++.

just suggestion, it has not yet tried.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM