库名称不以 lib 开头的 Libtool

Libtool with library names that do not start with lib

我正在尝试使用 libtool 将项目转换为 autotools。目标是针对第三方库 link 的共享库。原始 Makefile 方法使用以下命令行:

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

这个link没问题。

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

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

现在,第三方库名称不是lib开头。名字只是简单的thirdparty.lib。 linking 时,我得到如下命令行:

/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

这无法 link 与:

*** 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,它 link 没问题。

我怎样才能让 libtool 不改变地使用库名?我尝试直接拉入文件,例如:

libmycomponent_la_LIBADD += /path/to/thirdparty.lib

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

我也试过:

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

按照建议 here,但消息更改为无法找到 lib:thirdparty.lib

"The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories"。仅指定文件 thirdparty.lib(不带 -l)

解决方案是通过 libtool 隐藏链接器命令行参数。这是建议here, and fully documented in the libtool FAQ。所以,我调整了我的Makefile.am

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

现在链接很愉快。