是否可以链接一些—但并非全部使用 libtool 静态库?
我正在开发一个使用 autoconf、automake 和 libtool 构建的项目。该项目以二进制和源代码形式分发。
在 Linux 上,默认情况下构建脚本动态链接到所有库。这是有道理的,因为 Linux 用户可以依靠其发行版的包管理器来处理依赖关系。
在 Windows 上,默认情况下,构建脚本使用 libtool 的 -all-static
选项静态链接到所有库。这是有道理的,因为 Windows 没有提供任何依赖项,并且能够分发包含所有依赖项的单个二进制文件而不是浪费大量的 DLL 是很有帮助的。
在 OSX 上,有些依赖项是由操作系统提供的,有些则不是。因此,动态链接到操作系统提供的库和静态链接到其他库会很有帮助。不幸的是,libtool 的全有或全无的 -all-static
选项在这里没有帮助。
有没有一种好方法可以让 libtool 静态链接到一些库,但不是全部?
注意:我意识到我可以仔细编译依赖项,以便只有静态构建可用。但是,我希望我的项目的构建系统在静态和依赖项动态构建的常见情况下是健壮的。
注意:当然,我并不关心像 C/C++ 运行时库这样的低级依赖关系,它们总是在上述所有三个平台上动态链接。
I am working on a project which is built using autoconf, automake and libtool. The project is distributed in both binary and source form.
On Linux, by default the build script links to all libraries dynamically. This makes sense since Linux users can rely on their distribution’s package manager to handle dependencies.
On Windows, by default the build script links to all libraries statically using libtool’s -all-static
option. This makes sense since none of the dependencies are provided with Windows, and it’s helpful to be able to distribute a single binary containing all dependencies rather than mucking about distributing tons of DLLs.
On OSX, some of the dependencies are provided by the OS, and some are not. Therefore it would be helpful to link to the OS-provided libraries dynamically and to the other libraries statically. Unfortunately libtool’s all-or-nothing -all-static
option is not helpful here.
Is there a good way to get libtool to link to some libraries statically, but not all?
Note: I realise I could carefully compile the dependencies so that only static builds are available. However, I’d rather the build system for my project were robust in the common case of static and dynamic builds of dependencies being available.
Note: Of course, I am not concerned with really low level dependencies like the C/C++ runtime libraries, which are always linked dynamically on all three of the above platforms.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一番研究,我回答了我自己的问题。
如果您安装了库的静态和动态构建,并且使用
-l
参数链接到该库,则 libtool 会优先链接到动态构建。如果没有可用的动态构建,或者传递-static
或-all-static
选项,它会链接到静态构建。通过提供该库的完整路径来代替
-l
选项,可以强制 libtool 链接到静态库。After some research I have answered my own question.
If you have static and dynamic builds of a library installed, and you link to that library using the
-l
parameter, libtool links by preference to the dynamic build. It links to a static build if there is no dynamic build available, or if you pass the-static
or-all-static
options.libtool can be forced to link to the static library by giving the full path to that library in place of the
-l
option.