具有不以lib开头的库名的Libtool

时间:2018-03-14 22:01:38

标签: autotools autoconf automake libtool

我尝试使用libtool将项目转换为autotools。目标是链接第三方库的共享库。原始的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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

解决方案是通过libtool偷取链接器命令行参数。建议https://stats.stackexchange.com/a/296277,并在here中完整记录。所以,我用Makefile.am调整了:

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

现在很开心了。