Linux gcc - /usr/bin/ld 错误:在 /usr/local/lib 中找不到 <library> 尽管 ldconfig 列出了它,并且路径已添加到 ld.so.conf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19737996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:15:25  来源:igfitidea点击:

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

c++linuxgccld

提问by allan.simon

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

我尝试使用我手动编译并安装在 /usr/local/lib 中的库来编译 C++ 代码

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++ 默认不搜索 in /usr/local/lib,同样clang++

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

however the fact is /usr/local/libis in my /etc/ld.so.confand I did run ldconfigas root, and actually running ldconfig -p | grep cppdbshows me

然而事实是/usr/local/lib在我的/etc/ld.so.conf,我确实ldconfig以 root 身份运行,实际运行ldconfig -p | grep cppdb显示我

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/libof course solve the problem, but the goal is to use configuration files

添加选项-L/usr/local/lib当然可以解决问题,但目的是使用配置文件

采纳答案by Ignacio Vazquez-Abrams

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

ld,链接器,不使用外部配置文件。ldconfig用于装载机,ld.so。如果您想在某处为链接器设置值,请创建一个 makefile。

回答by liuyang1

  1. You can use linker script, and add '/usr/local/lib' to search_dir. see this Linker_Scriptsto 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++.

  1. 您可以使用链接描述文件,并将“/usr/local/lib”添加到 search_dir。请参阅此Linker_Scripts以获取更多详细信息。

  2. 将 /usr/local/lib 添加到 GCC_EXEC_PREFIX shell 环境中,然后再试一次。更多细节在g ++的“man”中搜索print-search-dirs。

just suggestion, it has not yet tried.

只是建议,还没试过。

回答by jjlin

Specifying -Lswitches 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.

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