【问题标题】:Libtool with library names that do not start with lib具有不以 lib 开头的库名称的 Libtool
【发布时间】:2018-08-23 14:34:36
【问题描述】:

我正在尝试使用 libtool 将项目转换为自动工具。目标是链接到第三方库的共享库。最初的 Makefile 方法使用以下命令行:

i686-w64-mingw32-g++ -g -shared -o libmycomponent.dll obj/mycomponent.o -L/path/to/thirdpary -lthirdpary -lwinpthread -lws2_32 -liphlpapi

这个链接很好。

但是,当转换为 autotools/libtool 时,我的 Makefile.am 中有:

libmycomponent_la_LIBADD += -L/path/to/thirdparty -lthirdparty

现在,第三方库名称lib 开头。这个名字只是thirdparty.lib。链接时,我得到如下命令行:

/bin/bash ./libtool  --tag=CXX   --mode=link i686-w64-mingw32-g++ -std=gnu++11 -I./include -g -O2 -shared -no-undefined --enable-runtime-pseudo-reloc -version-info 1:0:0 -L/path/to/thirdparty  -o libmycomponent.la -rpath /usr/local/lib src/libmycomponent_la-mycomponent.lo -lthirdcomponent -lwinpthread -liphlpapi -lws2_32

这无法链接到:

*** Warning: linker path does not have real file for library -lthirdpary.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libthirdpary but no candidates were found. (...for file magic test)
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.

*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.

但是,如果我将thirdparty.lib 复制到libthirdparty.lib,则链接正常。

如何让 libtool 使用未更改的库名称?我尝试直接拉入文件,例如:

libmycomponent_la_LIBADD += /path/to/thirdparty.lib

但我最终得到了未定义的符号(好像它甚至没有尝试拉入文件——这是有道理的,因为它不是 libtool 文件)。

我也试过这样做:

libmycomponent_la_LIBADD += -L/path/to/thirdparty -l:thirdparty

按照推荐的here,但消息变为找不到lib:thirdparty.lib

【问题讨论】:

  • @AndrewHenle 有趣的是,我可以在命令行上执行此操作。原始的纯 Makefile 方法链接很好。我将用示例更新问题。
  • 变量libmycomponent_la_LIBADD的最终完整值是多少?我无法从你提供的片段中看出。如果您最终得到不同的图书馆订单,那么这很可能解释了您的问题。
  • @JohnBollinger 似乎 libtool 以某种方式过滤掉了一些东西。我将set -x 添加到libtool,我看到它正在积极寻找libthirdparty。 libtool 预先添加“lib”,然后执行搜索。

标签: autotools autoconf automake libtool


【解决方案1】:

解决方案是通过 libtool 偷偷链接器命令行参数。这是建议here,并在libtool FAQ 中有完整记录。所以,我调整了我的Makefile.am

libmycomponent_la_LIBADD += -Wl,-L/path/to/thirdparty -Wl,-lthirdparty

现在它愉快地链接了。

【讨论】:

    【解决方案2】:

    “使用 -l 选项和指定文件名的唯一区别是 -l 用‘lib’和‘.a’包围库并搜索多个目录”。仅指定文件thirdparty.lib(不带-l)

    【讨论】:

    • 感谢您的提示。这确实消除了找不到真正库的错误。但现在我得到了未定义的引用。我试过:libmycomponent_la_LIBADD += -L/path/to/thirdparty thirdpartylibmycomponent_la_LIBADD += -L/path/to/thirdparty thirdparty.lib。两者都会导致未定义的引用。
    • "在命令中编写此选项会有所不同;链接器按照指定的顺序搜索和处理库和目标文件。因此,'foo.o -lz bar.o'在文件 foo.o 之后但在 bar.o 之前搜索库 'z'。如果 bar.o 引用了 'z' 中的函数,则可能不会加载这些函数。 .请检查顺序。
    • 这似乎是 libtool 问题,而不是链接器问题。我知道-l 是如何工作的,但-l 甚至没有通过libtool 进入链接器命令行。如果我手动链接,即使使用-lthirdparty 也可以正常工作。
    • 未解决。我正试图弄清楚如何说服 libtool 不过滤掉第三方库。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 2020-10-08
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多