【问题标题】:How do I make the c++ compiler search for libraries in /usr/local/lib?如何让 c++ 编译器在 /usr/local/lib 中搜索库?
【发布时间】:2013-07-21 18:48:50
【问题描述】:

我在 Mac 上使用 clang,但我认为这个问题对于 gcc(以及任何其他 unix 系统——希望如此)会有相同的答案。

现在,我无法链接到 libboost,因为它位于 /usr/local/lib 中。当然,我可以使用 -L/usr/local/lib 并将 LD_LIBRARY_PATH 设置为包含 /usr/local/lib 来实现它,但我希望我的系统无需搜索库并包含在 /usr/local 中在命令行中指定它。

有没有办法做到这一点?

【问题讨论】:

标签: c++ gcc compiler-construction shared-libraries clang


【解决方案1】:

要让您的系统自动执行此操作,您可以将环境变量 LIBRARY_PATH (Enviroment Variables) 指定到库目录 (/usr/local/lib)。

要使其永久化,只需在 .bashrc 或类似名称中声明此变量即可。

另一种方法是更改​​gcc的specs

确实,这是对这个问题的总结:How to add a default include path for gcc in linux?

【讨论】:

  • 这不是真正正确的方法,请看这个答案:stackoverflow.com/a/4743253/1598080
  • 这使得系统可以找到共享库,但问题仍然在于如何编译。所以这并不能解决这个问题。确实,查看“环境变量”链接,它说:LIBRARY_PATH ... Linking using GCC also uses these directories when searching for ordinary libraries for the -l option
  • 来自man ld(对于 GNU ld):The linker uses the following search paths to locate required shared libraries: ... 8. For a native linker on an ELF system, if the file /etc/ld.so.conf exists, the list of directories found in that file.
  • 对于 osx,您可能会看到类似于 ldconfig(8) for freebsd
猜你喜欢
  • 2011-06-12
  • 1970-01-01
  • 2014-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-13
  • 2013-07-27
  • 1970-01-01
相关资源
最近更新 更多