简体   繁体   English

自动工具生成Makefile时,多个程序共享一个源文件

[英]Multiple programs share a source file when autotools generating makefiles

This question concerns mostly Unix/Linux style C development. 这个问题主要涉及Unix / Linux风格的C开发。 I am using autotools to generate Makefile . 我正在使用autotools生成Makefile

There are two programs share a source file named utils.c . 有两个程序共享一个名为utils.c的源文件。

The structure of my source tree goes like this: 我的源代码树的结构如下:

app/
    src/
        server/
            server.c
            ...
        client/
            client.c
            ...
    include/

The question is where should I put the shared source file and how should I write my Makefile.am or configure.ac to make it work. 问题是我应该在哪里放置共享源文件,以及如何编写Makefile.amconfigure.ac以使其正常工作。

The current configure.ac only specify the AC_CONFIG_FILES([Makefile src/Makefile]) 当前的configure.ac仅指定AC_CONFIG_FILES([Makefile src/Makefile])

And the current src/Makefile.am goes like this: 当前的src/Makefile.am如下所示:

bin_PROGRAMS = server client
server_SOURCES = server/server.c
client_SOURCES = client/client.c
server_LDADD = $(DONT_KNOW_WHAT_TO_WRITE)
client_LDADD = $(DONT_KNOW_WHAT_TO_WRITE)

Thanks. 谢谢。

If it is just one relatively small source file, you might as well add it to the respective _SOURCES lines. 如果它只是一个相对较小的源文件,则最好将其添加到相应的_SOURCES行中。

If the shared code consists of multiple files, you could create a static library. 如果共享代码包含多个文件,则可以创建一个静态库。 https://www.gnu.org/software/automake/manual/html_node/A-Library.html https://www.gnu.org/software/automake/manual/html_node/A-Library.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM