【问题标题】:GNU ld cannot find library which is thereGNU ld 找不到那里的库
【发布时间】:2011-03-14 08:49:03
【问题描述】:

我在这里玩弄的包是相当未知的,但问题是相当普遍的。基本上,我正在尝试用 C++ 扩展编译 Python 模块(称为 rql)。该扩展使用名为 gecode 的外部框架,其中包含多个库。我编译了gecode并在本地安装。现在,让输出自己说话:

red@devel:~/build/rql-0.23.3$ echo $LD_LIBRARY_PATH
/home/red/usr/lib
red@devel:~/build/rql-0.23.3$ ls $LD_LIBRARY_PATH | grep libgecodeint 
libgecodeint.so
libgecodeint.so.22
libgecodeint.so.22.0
red@devel:~/build/rql-0.23.3$ python setup.py build
running build
running build.py
package init file './test/__init__.py' not found (or not a regular file)
running build_ext
building 'rql_solve' extension
g++ -pthread -shared build/temp.linux-i686-2.5/gecode-solver.o -lgecodeint -lgecodekernel -lgecodesearch -o build/lib.linux-i686-2.5/rql_solve.so
/usr/bin/ld: cannot find -lgecodeint
collect2: ld returned 1 exit status
error: command 'g++' failed with exit status 1

【问题讨论】:

  • LD_LIBRARY_PATH 是否导出到您的环境中?
  • 在您的 LD_LIBRARY_PATH 中的 libgecodeint.so 是否适用于正确的架构(例如 32 位或 64 位,视情况而定)?

标签: c++ linker shared-libraries ld library-path


【解决方案1】:

LD_LIBRARY_PATH 用于运行时链接器/加载器(ldconfig 可以达到相同的效果)。你需要的是-L 标志:

-L/home/red/usr/lib

在编译器命令行上。

编辑:

而且 - 感谢 @bjg 提醒我 - 如果您不想弄乱编译器选项,可以使用 LIBRARY_PATH

【讨论】:

  • 是的,如果可以的话,我会将他的评论标记为答案:) ld 无论如何都没有查看它的运行时搜索路径,这有点奇怪,但现在问题已经解决了,非常感谢你和其他人在这里!
【解决方案2】:

您显然已修改 LD_LIBRARY_PATH 以指向您主目录中的非标准位置。你知道在 setup.py 中调用 g++ 的环境中的LD_LIBRARY_PATH 是否和你的 shell 环境匹配?

看看您是否可以将参数传递给setup.py 以修改库路径,或者只是将-L/home/red/usr/lib 传递给g++。

【讨论】:

  • g++ 将使用LIBRARY_PATH(如果存在),因此您可以尝试LIBRARY_PATH=/red/usr/lib python setup.py build
猜你喜欢
  • 2019-02-23
  • 1970-01-01
  • 1970-01-01
  • 2014-12-13
  • 1970-01-01
  • 1970-01-01
  • 2021-10-24
  • 2017-03-31
  • 1970-01-01
相关资源
最近更新 更多