【发布时间】: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