【发布时间】: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 消息
它确实有效。
谁能告诉我我错过了什么?
【问题讨论】: