【发布时间】:2012-02-24 16:37:49
【问题描述】:
1) 我有一个项目包含一个链接到一些外部库(即gcrypt、gpg-error、z 和ssh2)的共享库。让我们称之为“mylib”。
这个库构建完美,我可以看到libtool 正确链接了依赖项。
libtool: link: ppc-linux-gcc -shared -fPIC -DPIC .libs/mylib1.o .libs/mylib2.o .libs/mylib3.o
-Wl,-rpath -Wl,/opt/ELDK/ppc_8xx/lib -Wl,-rpath \
-Wl,/opt/ELDK/ppc_8xx/lib /opt/ELDK/ppc_8xx/lib/libssh2.so \
-L/opt/ELDK/ppc_8xx/lib -lz /opt/ELDK/ppc_8xx/lib/libgcrypt.so \
/opt/ELDK/ppc_8xx/lib/libgpg-error.so -lpthread -O2 \
-Wl,-soname -Wl,mylib.so.0 -o .libs/mylib.so.0.0.0
2) 同一个项目有几个链接到“mylib”的程序。 但是,当我尝试链接它们时,我收到了关于相同先前库的链接器错误:
/opt/ELDK-3.1/usr/bin/../lib/gcc-lib/ppc-linux/3.3.3/../../../../ppc-linux/bin/ld: \
warning: libssh2.so.1, needed by ./../myLib/.libs/mylib.so, not found (try using -rpath or -rpath-link)
/opt/ELDK-3.1/usr/bin/../lib/gcc-lib/ppc-linux/3.3.3/../../../../ppc-linux/bin/ld: \
warning: libz.so.1, needed by ./../myLib/.libs/mylib.so, not found (try using -rpath or -rpath-link)
/opt/ELDK-3.1/usr/bin/../lib/gcc-lib/ppc-linux/3.3.3/../../../../ppc-linux/bin/ld: \
warning: libgcrypt.so.11, needed by ./../myLib/.libs/mylib.so, not found (try using -rpath or -rpath-link)
/opt/ELDK-3.1/usr/bin/../lib/gcc-lib/ppc-linux/3.3.3/../../../../ppc-linux/bin/ld: \
warning: libgpg-error.so.0, needed by ./../myLib/.libs/mylib.so, not found (try using -rpath or -rpath-link)
./../myLib/.libs/mylib.so: undefined reference to `libssh2_channel_process_startup'
./../myLib/.libs/mylib.so: undefined reference to `libssh2_scp_send_ex'
在“mylib”configure.ac 我明确搜索库:
AC_SEARCH_LIBS(gpg_err_set_errno,[gpg-error])
AC_SEARCH_LIBS(gcry_check_version,[gcrypt])
AC_SEARCH_LIBS(deflate,[z])
AC_SEARCH_LIBS(libssh2_init,[ssh2])
我还必须使用“mylib”在每个项目中明确包含所有这些库吗? 当我第一次在“mylib”中链接它们时,它不应该已经解决了吗?
有没有更好的方法来做到这一点?
谢谢。
P.S.:我在autoconf这件事上不是很聪明,对不起。
注意:我正在使用(还很旧的)ELDK 3.1 为 PowerPC 进行交叉编译。
【问题讨论】:
-
您是否覆盖了 Makefile.am 中程序的任何指令?
-
我有类似
program1_CPPFLAGS = -I$(top_srcdir) $(MYLIB_CFLAGS)的东西,其中MYLIB_CFLAGS和MYLIB_LIBS在“program1”的configure.ac中定义为AC_ARG_WITH,以允许我链接到本地“mylib”而不是一个系统安装了一个(请告诉我这是否是一种更好的方法)。 -
CPPFLAGS 应该不相关,但是如何在 Makefile.am 中使用 MYLIB_LIBS?在您的最终 Makefile 中,应该有一个包含 $(LINK) 命令的 program1$(EXEEXT) 的目标,并且该命令应该有 $(LIBS),如果 AC_SEARCH_LIBS 成功找到给定的库,则它应该包含库。
-
在 mylib.so 上运行 ldd 的输出会很有用,尽管我不确定在交叉编译时这样做有多容易。同样有趣的是检查
readelf -a以确保 RPATH 确实按照您的要求添加。
标签: c cross-compiling autoconf automake