通过一次安装生成静态库和可执行文件(autoconf)

发布于 2024-07-25 23:50:11 字数 178 浏览 4 评论 0原文

我知道如何构建项目或如何使用 autoconf 创建库。

我想要实现的是生成一个静态库并使用该库在单个配置/制作/制作安装运行中构建项目。

我希望将一些源文件放入库中,其余部分使用该库进行编译。

如何修改 makefile.am 文件和 configure.ac 才能使其正常工作?

I know how to build a project or how to create a library using autoconf.

What I want to achive is to generate a static library and use this library to build a project in a single configure/make/make install run.

I want some source files to be put into library and the rest to be compiled using this library.

How do I modify makefile.am files and configure.ac to get it working?

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

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

发布评论

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

评论(1

骷髅 2024-08-01 23:50:12

最简单的方法是使用 libtool 和 automake “便利库”。
这是一个最小的例子
对于 Makefile.am

lib_LTLIBRARIES = libExample.la 
libExample_la_SOURCES = lfile1.C 
bin_PROGRAMS = test
test_SOURCES = tfile1.C 
test_LDADD = libExample.la 

对于 configure.ac

AC_INIT(test, 1.0)
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_LTDL_DLLIB
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

这将在目录 .libs 中构建静态和动态库 libExample。
如果您只想要一个静态库,可以将 --disable-shared 传递给 configure

The easiest way to do this is with libtool and automake "convenience libraries".
Here is a minimal example
for Makefile.am

lib_LTLIBRARIES = libExample.la 
libExample_la_SOURCES = lfile1.C 
bin_PROGRAMS = test
test_SOURCES = tfile1.C 
test_LDADD = libExample.la 

for configure.ac

AC_INIT(test, 1.0)
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_LTDL_DLLIB
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

This will build both a static and dynamic library libExample in the directory .libs.
If you want just a static library, you can pass --disable-shared to configure.

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