【问题标题】:configure finds library, but ldd does not配置找到库,但 ldd 没有
【发布时间】:2013-06-07 12:35:40
【问题描述】:

我正在另一个库 libmsg 中使用一个名为 liblogger 的日志记录库(我已实现)。对于他们两个,我都在使用自动工具。我在我的系统中成功安装了 liblogger 库,在 /usr/local/lib 目录下。

在其他libmsg的configure.ac脚本中,我验证系统中是否安装了liblogger,如下:

AC_CHECK_LIB([logger],
             [log_init],
             [],
             [
              echo "Error: Could not find liblogger."
              exit 1
             ])

并将“-L/usr/local/lib”路径添加到 LDFLAGS 变量中。

AC_CHECK_LIB 测试找到库,libmsg 库及其使用的 check_PROGRAMS 均已成功编译。

但是,当我尝试执行测试程序时,我得到了错误:

加载共享库时出错:liblogger.so.0:无法打开共享对象文件:没有这样的文件或目录

确实,ldd 也没有找到该库:

$ ldd msgs
  linux-vdso.so.1 => (0x00007fff543ff000) 
  liblogger.so.0 => not found
  libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fdf329ad000)

但库实际上就在那里,在 /usr/local/lib 中。

为了链接测试程序,libtool 被调用,指令如下:

$ /bin/bash ../libtool --tag=CC   --mode=link gcc -I../include -I../msg -L/usr/local/lib -O2 -Wall -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include   -I/usr/local/include -I/usr/local/lib  -L/usr/local/lib -o msgs msgs.o message.o base64.o misc.o  -llogger  -lglib-2.0

这实际上与以下内容相呼应:

libtool: link: gcc -I../include -I../msg -O2 -Wall -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include -I/usr/local/lib -o msgs msgs.o message.o base64.o misc.o  -L/usr/local/lib /usr/local/lib/liblogger.so -lglib-2.0

所以,-llogger 标志被 -L[..] /usr/local/liblogger.so 取代(我想这是正确的行为?我还不能确定...)

实际上,如果我调用测试程序:

LDPRELOAD=/usr/local/lib/liblogger.so 消息

它确实有效。

谁能告诉我我错过了什么?

【问题讨论】:

    标签: autoconf libtool ldd


    【解决方案1】:

    您需要检查是否:

    • /usr/local/lib/etc/ld.so.conf 中(通常是这些天)。
    • ldconfig 在您安装 liblogger 时运行。如果没有,请运行它。
    • liblogger.so.0 实际上在 /usr/local/lib 中。

    【讨论】:

    • ldconfig 实际上并未运行。确实解决了问题,谢谢。有没有办法让 libtool 自动执行?
    • libtool 不应执行 ldconfig。甚至make install 说在之后运行ldconfig,而不是自己运行。通常包管理器(RPM、apt 等)会运行它,因为它实际上只需要在第一次安装 lib 时(以及卸载后)运行。运行 ldconfig 它通常也需要 root 权限。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多