[英]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.