使用 autotools/libtool 构建 .so 模块,无需安装 .la 和 .a 变体
如何在没有 .la 和 .a 库的情况下使用 autotools/libtool 构建和安装 .so 模块 也被安装到 --prefix 路径中?
目前我正在使用以下Makefile.am:
lib_LTLIBRARIES = libCurlDownloader.la
libCurlDownloader_la_SOURCES = Curl.cpp
libCurlDownloader_la_LDFLAGS = -module -avoid-version
它可以工作,但是除了libCurlDownloader.so之外,它还安装了libCurlDownloader.la和libCurlDownloader.a,这是不可取的。
更新 #1
可以通过
./configure --disable-static
使用或
AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)
在configure.ac中
来使.a不被生成,但仍然是一个问题,如何使.la不被安装到安装--prefix中,同时具有.so安装了。
更新 #2
可以使用以下命令从安装中删除 .la 文件 --prefix
install-exec-hook: find $(DESTDIR)$(libdir) -type f -name \*.la -delete
How to build and install a .so module with autotools/libtool without .la and .a libraries
being also installed into --prefix path?
Currently i am using following Makefile.am:
lib_LTLIBRARIES = libCurlDownloader.la
libCurlDownloader_la_SOURCES = Curl.cpp
libCurlDownloader_la_LDFLAGS = -module -avoid-version
It works, but in addition to libCurlDownloader.so it also installs libCurlDownloader.la and libCurlDownloader.a, what is undesirable.
Update #1
It is possible to make .a not be generated, by using either
./configure --disable-static
or
AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)
in configure.ac
But it is still the question how to make .la not being installed into installation --prefix while having .so installed.
Update #2
It is possible to remove .la files from installation --prefix using
install-exec-hook: find $(DESTDIR)$(libdir) -type f -name \*.la -delete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必删除
.la
文件。.la
文件包含在两种情况下使用的信息:针对构建的库进行静态链接。静态链接时(即
.a
与-static
),没有有关所链接库的依赖项的信息,因此 libtool 可以使用中的信息>.la
文件来创建引用所有必要依赖项的适当ld
命令。这在像 MinGW 这样的环境中通常更为重要,其中链接器需要以特定顺序指定多个相同的库来解决递归依赖关系。仅当您打算构建静态二进制文件时,这才是一个问题。在某些平台上动态加载构建库(即,如果使用
libltdl
,则使用lt_dlopen
)。同样,在某些平台上,编译模块的依赖项不会编码在二进制文件中,因此需要.la
文件,以便lt_dlopen
找到并加载正确的依赖项。在 ELF 平台(包括 Linux)和 PE 平台(即 Windows)上,依赖项存储在库中,因此lt_dlopen
无需.la
文件即可工作。 MacOS 上的 MachO 格式在构建捆绑包时可能需要.la
文件。Debian/Ubuntu 打包者决定从其软件包中排除
.la
文件,因为第二个原因在 Linux 上不合适,并且他们希望您一开始就不要构建静态二进制文件。在 libtool 设计支持的其他平台上,可能需要.la
文件来链接或运行程序。You should not necessarily delete the
.la
files. The.la
files contains information that is used in two situations:Statically linking against the built library. When statically linking (i.e.,
.a
with-static
), there is no information about the dependencies of the library being linked, so libtool can use the information in the.la
file to create an appropriateld
command referencing all the necessary dependencies. This is often more important on an environment like MinGW where the linker requires the same library specified multiples in a particular order to resolve recursive dependencies. This is only a concern if one intends to build a static binary.Dynamically loading the build library on some platforms (i.e., with
lt_dlopen
if usinglibltdl
). Similarly, on certain platforms, dependencies of the compile module are not encoded in the binary, so the.la
file is needed so thatlt_dlopen
will find and load the correct dependencies. On ELF platforms (including Linux) and PE platforms (i.e., Windows), the dependencies are store in the library, solt_dlopen
will work without the.la
files. The MachO format on MacOS can require.la
files when building bundles.The Debian/Ubuntu packagers have decided to exclude
.la
files from their packages because the second reason isn't appropriate on Linux and they would prefer you didn't build static binaries in the first place. On other platforms, which libtool is designed to support, the.la
files may be needed for linking or running the program.我偶然发现了这个问题,因为它使用了术语“模块”,在 automake/libtool 中它是插件的术语。我在 Finit 中有一个插件系统,因此我使用“-module”构建插件以避免创建 .a 文件。但我仍然安装了 .la 文件,这实际上甚至不适用于“-module”情况。
我还没有找到一种有记录的方法来跳过插件的 .la 文件,但我是这样做的:
要明确的是,在我的用例中,没有人会“链接”我的插件 .so,所以.la 文件确实没有用。
I stumbled upon this question because it used the term "module", which in automake/libtool speak is the term for a plugin. I have a plugin system in Finit, so I build my plugins with '-module' to avoid creating .a files. But I still get the .la files installed, which really is not even applicable in the '-module' case.
I've yet to find a documented way to skip .la files for plugins, but here is how I do it:
To be clear, in my use-case there is nobody going to "link" against my plugin .so's, so the .la files really are of no use.