如何为使用第三方库的 C 程序设置成熟的构建过程(APR - Apache Portability Runtime)

发布于 2024-10-12 23:25:15 字数 733 浏览 3 评论 0原文

我编写了一个由许多文件组成的 C 程序,并使用 APR (http://apr.apache.org) - 它包括它的头文件,我更喜欢动态链接它的库。

我的问题是,目前我对开发站点上设置的 APR 标头的路径和我找到的静态 APR 库的路径进行了硬编码。

这就是我的 Makefile 的样子(我重命名了一些位):

my_program: file1.c file2.c file3.c file4.c file5.c file6.c file7.c
    @rm -f $@
    $(CC) -std=c99 -pedantic -D_POSIX_C_SOURCE -I/usr/local/include/apache -L/usr/local/lib -lapr-1 $(CFLAGS) $^ -o $@

显然 APR 静态库文件的名称是 libapr-1.a,但我也有 libapr-1.so< /code> 和 libapr-1.so.0 甚至 libapr-1.la 我什至不知道是什么。因此,实际上,我怀疑现在我正在静态链接到 APR。除了我的目标是建立一个受人尊敬的构建系统之外,我还想动态链接到 APR。

我是否有一种常见的做法来设置一个自动化构建,该构建不仅现在适合我,而且对于其他人构建我的程序也足够灵活?我闻到了 autotools 的味道,但我对它们的经验绝对为零,并且现在想满足于下一个最好的事情。我有什么选择?

I have written a C program that consists of a number of files, and uses APR (http://apr.apache.org) - it includes its headers and I would prefer dynamic linking of its libraries.

My problem is that currently I hard-code both the paths to APR headers as set up at my development site and the paths of the static APR library I have found.

This is what my Makefile looks like (i renamed some bits):

my_program: file1.c file2.c file3.c file4.c file5.c file6.c file7.c
    @rm -f $@
    $(CC) -std=c99 -pedantic -D_POSIX_C_SOURCE -I/usr/local/include/apache -L/usr/local/lib -lapr-1 $(CFLAGS) $^ -o $@

Obviously the name of the APR static library file is libapr-1.a, but I also have libapr-1.so and libapr-1.so.0 and even libapr-1.la which I am not even sure what is. So, in effect, I suspect that right now I am linking to APR statically. Aside from my goal of a respectable build system, I would like to link to APR dynamically.

Is there a common practice for me to set up an automated build that will work not only for me now, but also is flexible enough for others to build my program? I smell the proximity of the autotools, but I have absolutely zero experience with them, and would like for now to settle for the next best thing. What options do I have?

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

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

发布评论

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

评论(1

逆蝶 2024-10-19 23:25:15

默认情况下,链接器将拾取共享库(.so),如果没有找到静态库(.a)。
因此,当您传递给链接器 -lapr-1 时,它将完全符合您的要求。

为了确保您的二进制文件确实将使用共享库,请运行:

ldd your_binary

您应该在输出列表中看到 apr 库。

By default linker will pickup shared library (.so) and if it not found static library (.a).
So when you pass to linker -lapr-1 it will exectly what you want.

To ensure that your binrary indeed will use shared library run:

ldd your_binary

You should see apr library in output list.

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