【问题标题】:autotools: one project with one executable, one shared obj and a "shared" internal libraryautotools:一个项目,一个可执行文件,一个共享 obj 和一个“共享”内部库
【发布时间】:2013-04-15 21:43:37
【问题描述】:

我正在尝试使用自动工具。我有以下项目层次结构:

    project/src
    project/src/utilities
    project/src/utilities/util.c
    project/src/utilities/util.h
    project/src/sharedObject
    project/src/sharedObject/sharedObject.c
    project/src/sharedObject/sharedObject.h
    project/src/sharedObject/thing.c
    project/src/executable
    project/src/executable/exec.c
    project/src/executable/exec.h
    project/src/executable/thing1.c
    project/src/executable/thing2.c

"executable" 和 "sharedObject.so" 都依赖于 "util.o" 和 "util.h"。我已经看到了创建便利库的示例,但我不确定如何在其他两个子项目的 "Makefile.am" 文件中指定它们。这些项目间的依赖是如何定义的?

"executable" 和 "sharedObject.so" 都将被安装。 "util.o" 和 "util.h" 文件只会在构建过程中使用。

谢谢

【问题讨论】:

  • 在深入了解 autotools 之前,我建议您先了解一下 CMake。我发现它比 autotools 更容易使用。但是,如果您正在以传统风格制作开源软件,则需要使用 autotools。

标签: c autotools libtool


【解决方案1】:

在utilities/Makefile.am:

noinst_LTLIBRARIES = libutil.la   
libutil_la_SOURCES = util.h util.c

在executable/Makefile.am中,库的使用应该使用LDADDprimary,例如,

bin_PROGRAMS = exec
exec_SOURCES = exec.h exec.c thing.h thing.c
exec_LDADD = ../utilities/libutil.la

在sharedObject/Makefile.am 中,使用LIBADD 主要:

lib_LTLIBRARIES = sharedObject.la
sharedObject_la_SOURCES = sharedObject.h sharedObject.c thing.c
sharedObject_la_LIBADD = ../utilities/libutil.la

如果你真的想要一个动态加载的sharedObject.so,你还需要:

sharedObject_la_LDFLAGS = -module

否则,目标应该被称为libsharedObject。


顶层 Makefile.am 应该 order SUBDIRS 以便首先构建依赖项:

SUBDIRS = utilities executable sharedObject

【讨论】:

  • 谢谢布雷特,我会在早上试试!
猜你喜欢
  • 2015-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-27
  • 2013-04-01
  • 1970-01-01
相关资源
最近更新 更多