c - 初学者编写makefile;检查我的 Makefile

标签 c makefile linker flags automake

我想了解如何为小项目编写自己的 makefile,所以我有几个问题 我的项目包括 src包含 main.c 的目录, file1.c , file2.c , header1.h ,最后 header2.h这些文件使用了我创建的非标准库中的一些库和非标准头文件,库目录位于 usr/lib/pr__lib头目录位于usr/include/lib
所以我应该创建两个 makefile.am一个将位于 src目录,另一个将在项目的根目录中 makefile.amsrc目录如下:

 program_NAME := PRDSL

 bin_PROGRAMS = PRDSL_AutoProject

 program_INCLUDE_DIRS := /usr/bin/PR__bin

 program_LIBRARY_DIRS := /usr/lib/PR__lib

 CFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir))

 program_LIBRARIES := \
         libprdependency \
         libprdynarray_pic \
         libprhistogram_pic \
         libprlistofarrays \
         libprlistofarrays_pic \
         libprmalloc \
         libvreo_wrapper_library 

 AM_LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir))

 AM_LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library))

 PRDSL_AutoProject_SOURCES = \
         main.c \
         file1.c \
         file2.c

 depend :
      makedepend --$(CFLAGS) --$(PRDSL_AutoProject_SOURCES)

 all: $(program_NAME)

第二 makefile.am在根目录下如下图:

  SUBDIRS = src

  PRDSL_AutoProjectdocdir = ${prefix}/doc/PRDSL_AutoProject
  PRDSL_AutoProjectdoc_DATA = \
              README\
              COPYING\
              AUTHORS\
              ChangeLog\
              INSTALL\
              NEWS


     INTLTOOL_FILES = intltool-extract.in \
             intltool-merge.in \
             intltool-update.in

     EXTRA_DIST = $(PRDSL_AutoProjectdoc_DATA) \
             $(INTLTOOL_FILES)

     DISTCLEANFILES = intltool-extract \
             intltool-merge \
             intltool-update \
             po/.intltool-merge-cache


     # Remove doc directory on uninstall
     uninstall-local:
            -rm -r $(PRDSL_AutoProjectdocdir)

但我在运行时收到以下错误和警告 automake命令:

  src/Makefile.am:20: error: 'program_LIBRARIES' is used but 'programdir' is undefined
  src/Makefile.am:18: warning: 'CFLAGS' is a user variable, you should not override it;
  src/Makefile.am:18: use 'AM_CFLAGS' instead
  src/Makefile.am:43: error: AM_LDFLAGS must be set with '=' before using '+='

有人可以查看并帮助我吗?

最佳答案

对于 src/Makefile.am:43: error: AM_LDFLAGS must be set with '=' before using '+='my answer到你的previous question .

是的,下面几行告诉你使用 AM_CFLAGS而不是 CFLAGS因为,如错误所示,CFLAGS是用户指定的值,您应该保留它。

src/Makefile.am:18: warning: 'CFLAGS' is a user variable, you should not override it;
src/Makefile.am:18: use 'AM_CFLAGS' instead

我相信,虽然我还不确定,但你得到 src/Makefile.am:20: error: 'program_LIBRARIES' is used but 'programdir' is undefined 的原因是因为您正在使用变量 program_LIBRARIES autotools 认为这是一个他们应该使用的变量,但您没有以这种方式使用,而是在为 AM_LDFLAGS 设置值的循环中使用.因此,假设我是正确的,如果您将其重命名为不遵循 autotool 变量命名方案,我相信错误将会消失。

关于c - 初学者编写makefile;检查我的 Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27657900/

相关文章:

c++ - OpenAL:如何添加 ALUT

c++ - 生成文件 | Make 后清理 - 错误 : No such file or directory | Error: recipe for target * failed

makefile - 如何学习使用make?我永远无法使用 make 和 makefile 构建源代码

c - 关于 malloc() : writing outside of allocated memory

c - 在中断处理程序中将数据从内核缓冲区移动到用户空间缓冲区

macos - 没有规则可以制作目标 `/Makefile' ,需要 `Makefile'

c++ - 混合 C++ 和 Fortran 链接问题

c - 在 Visual Studio 2017 中的 errno 上收到链接错误 lnk2001

c - 根据包含索引的另一个数组的内容对 C char 数组进行排序

c - c/popen 中的 bash 找不到我的脚本