6

我正在开发一个使用 autoconf、automake 和 libtool 构建的项目。该项目以二进制和源代码形式分发。

在 Linux 上,默认情况下,构建脚本会动态链接到所有库。这是有道理的,因为 Linux 用户可以依靠其发行版的包管理器来处理依赖关系。

在 Windows 上,默认情况下,构建脚本使用 libtool 的-all-static选项静态链接到所有库。这是有道理的,因为 Windows 没有提供任何依赖项,并且能够分发包含所有依赖项的单个二进制文件而不是为分发大量 DLL 而烦恼是有帮助的。

在 OSX 上,一些依赖项由 OS 提供,而另一些则不提供。因此,动态链接到操作系统提供的库和静态链接到其他库会很有帮助。不幸的是,libtool 的全有或全无-all-static选项在这里没有帮助。

有没有一种好方法可以让 libtool 静态链接到一些库,但不是全部?

注意:我意识到我可以仔细编译依赖项,以便只有静态构建可用。但是,我希望我的项目的构建系统在依赖项的静态动态构建可用的常见情况下是健壮的。

注意:当然,我并不关心像 C/C++ 运行时库这样的低级依赖关系,它们总是在上述所有三个平台上动态链接。

4

1 回答 1

7

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.

于 2009-12-26T19:45:10.160 回答