简体   繁体   English

使用 automake/libtool 将共享库与 static 非 automake 生成的库链接

[英]Using automake/libtool to link shared library with static non-automake-generated lib

In my shared library foo I link static library bar as follows:在我的共享库 foo 中,我链接 static 库 bar 如下:

foo_la_LIBADD = /path/to/bar.lib

When linking, I get the following:链接时,我得到以下信息:

*** Warning: Trying to link with static lib archive /path/to/bar.lib.
*** 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 the file extensions .lib of this argument makes me believe
*** that it is just a static archive that I should not use here.

and the link fails.并且链接失败。

bar.lib is effectively an intermediate convenience archive, but it is not produced by automake. bar.lib 实际上是一个方便的中间存档,但它不是由 automake 生成的。

I can fix the issue by hand-generating a bar.la wrapper for bar.lib with我可以通过手动为 bar.lib 生成一个 bar.la 包装器来解决这个问题

old_library='bar.lib'
shouldnotlink=no

but that seems like a gruesome hack I would prefer to avoid.但这似乎是我宁愿避免的可怕黑客攻击。 Is there a better way to fix this?有没有更好的方法来解决这个问题?

Don't use libtool to link shared libraries on Windows if your library depends on other libraries. 如果您的库依赖于其他库,请不要使用libtool链接Windows上的共享库。 If you do, expect at the very least to create .la wrappers for any libraries not produced by autotools. 如果这样做,则至少应为不是由自动工具生成的任何库创建.la包装器。

Instead, you can create and maintain custom link rules for Windows using cl.exe or link.exe directly. 而是可以直接使用cl.exe或link.exe为Windows创建和维护自定义链接规则。 You can conditionally specify such rules in your Makefile.am and they will override the default libtool rule. 您可以在Makefile.am中有条件地指定此类规则,它们将覆盖默认的libtool规则。 This is far less trouble than fighting with libtool. 与使用libtool进行斗争相比,这要麻烦得多。

Adjust libtool.m4 (similar to this os2 patch ) - or the generated configure script - to generate调整 libtool.m4(类似于这个 os2 补丁) - 或者生成的配置脚本 - 生成

deplibs_check_method="pass_all" deplibs_check_method="pass_all"

in the generated libtool script;在生成的 libtool 脚本中; or (if you can do this after running configure) change it directly in there.或者(如果您可以在运行配置后执行此操作)直接在其中更改它。

This way you'll get a warning这样你会得到一个警告

*** Warning: Linking the shared library test.la against the
*** static library /path/to/bar.lib is not portable!

and everything will still link.一切仍将链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows上的CMake链接共享库(lib),但找不到dll - CMake link shared library(lib) on Windows but cannot find dll 使用 qmake 和 MSVC2015 创建共享库(.lib 和 .dll) - Create shared library (.lib and .dll) using qmake and MSVC2015 使用Mingw从源代码构建libvorbis:“您必须安装automake才能编译vorbis” - Building libvorbis from source using Mingw: “You must have automake installed to compile vorbis” 用静态库构建共享库 - Build shared library with static library 使用 setup.py 链接 library.lib - Link library.lib using setup.py Windows 上的 CMake 链接共享库 - CMake link shared library on Windows 如何在Windows机器上安装autotools(autoconf,automake,aclocal,libtoolize pkgconfig) - how to install autotools on windows machine(autoconf, automake, aclocal, libtoolize pkgconfig) 确定Windows上静态库(LIB)的CPU体系结构 - Determining the CPU architecture of a static library (LIB) on Windows 使用静态标准库构建Visual C ++静态库 - Build Visual C++ static library with static standard lib 如何使用 lib.exe 将一个 static 库与一个导入库(或两个 static 库)捆绑在一起? - How to bundle a static library with an import library (or two static libraries) with lib.exe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM