在自动工具项目中包含(仅标头)库

发布于 2024-10-05 09:18:57 字数 413 浏览 0 评论 0原文

我想在我的 Autotools 项目中集成一个仅包含头文件的 C++ 库。由于该库使用 Autoconf 和 A​​utomake,因此我使用 AC_CONFIG_SUBDIRSconfigure.ac 中,并将库目录添加到 Makefile.am 中的 SUBDIRS = 行。

我的问题是:如何防止 make install 安装头库?我正在构建一个二进制文件,因此我的用户不需要这些标头。

我不想篡改库,因此我可以通过解压新版本来获取升级。

I want to integrate a header-only C++ library in my Autotools project. Since the library uses Autoconf and Automake, I use AC_CONFIG_SUBDIRS in configure.ac and added the library dir to the SUBDIRS = line in Makefile.am.

My question is: how do I prevent the header library from being installed by make install? I'm building a single binary, so my users don't need these headers.

I'd prefer not to tamper with the library, so I can fetch upgrade by just untarring the new version.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心安伴我暖 2024-10-12 09:18:57

这是一个想法。

将所有您不想安装的第三方库移至名为 noinst/ 的子目录中。例如,如果您想将项目与 Boost 一起发布,请将其解压到目录 noinst/boost/ 中。使用AC_CONFIG_SUBDIRS([noinst/boost])。在 noinst/Makefile.am 中,执行如下操作:

SUBDIRS = boost
# Override Automake's installation targets with the command ":" that does nothing.
install:; @:
install-exec:; @:
install-data:; @:
uninstall:; @:

效果是,每当从顶级目录运行某些递归“make install*”或“make uninstall”命令时,递归将停在 noinst/ 处并且不访问其子目录。其他递归命令(如“make”、“make clean”或“make dist”)仍将递归到子目录中。

您当然可以直接将 install: 等覆盖到第三方包中,并避免额外的 noinst/ 目录。但如果您像我一样,您不想篡改第三方软件包以简化其更新。
上述设置的一个很好的特性是,如果有人进入 noinst/boost/ 并决定运行 make install,它就会起作用。当他们安装您的软件包时,默认情况下不会发生这种情况。

Here is an idea.

Move all the third-party libraries you do not want to see installed into a subdirectory called noinst/. So for instance if you want to ship your project with something like Boost, unpack it into the directory noinst/boost/. Use AC_CONFIG_SUBDIRS([noinst/boost]). Inside noinst/Makefile.am, do something like this:

SUBDIRS = boost
# Override Automake's installation targets with the command ":" that does nothing.
install:; @:
install-exec:; @:
install-data:; @:
uninstall:; @:

The effect is that whenever some of the recursive "make install*" or "make uninstall" commands are run from the top-level directory, the recursion will stop in noinst/ and not visit its subdirectories. Other recursive commands (like "make", "make clean" or "make dist") will still recurse into the subdirectories.

You could of course override install: and friends directly into the third-party package, and avoid the extra noinst/ directory. But if you are like me, you don't want to tamper with third-party packages to ease their update.
Also a nice property of the above setup is that if someone goes into noinst/boost/ and decide to run make install, it will work. It just does not occur by default when they install your package.

韶华倾负 2024-10-12 09:18:57

刚刚遇到类似的问题,并在automake手册:

noinst_HEADERS 是在仅包含标头且不包含关联库或程序的目录中使用的正确变量

Andreas

just came across a similar problem and found the solution in the automake manual:

noinst_HEADERS would be the right variable to use in a directory containing only headers and no associated library or program

Andreas

你げ笑在眉眼 2024-10-12 09:18:57

那么就不要使用SUBDIRS。以下 hack 可能会起作用:

all-local:
        ${MAKE} -C thatlib all

当然,如果该库保留在项目之外的自己的目录中,并且您只需通过 CFLAGS/LIBS 标志指向它,那将是最好的。

Don't use SUBDIRS then. The following hack may work:

all-local:
        ${MAKE} -C thatlib all

Of course it would be best if the library remained in its own directory outside of your project, and you just point to it via CFLAGS/LIBS flags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文