4

I have written complicated C and C++ makefiles in the past. However, I cannot seem to get my D makefile to work. It throws over a thousand lines of "undefined reference" errors, which look as if Phobos is failing to be linked. How can I fix that?

I am using GNU make and LDC2 on Fedora 19 Linux.

Edit: Compiling and linking directly using LDC2 works correctly. Only when invoked with 'make' is there an error. It seems that make is trying to invoke a separate linker.

Edit 2: Here is my makefile:

# This macro contains the source files
sources := $(wildcard *.d)

binaries := $(sources:%.d=%)

all: $(binaries)

%.o:%.d
        ldc2 $< -O5 -check-printf-calls

Deleting the .o fixed it.

4

1 回答 1

6

我不知道Pattern Rules的复杂性,但我相信这就是你的问题所在。

%.o:%.d
    ldc2 $< -O5 -check-printf-calls

您已要求 make 通过调用 ldc2 命令将每个 .d 文件转换为 .o。但是,您不是要求 ldc2 构建目标文件,而是要求它构建可执行文件(我不知道您想要哪个标志 dmd/gdc: -c)。虽然我会在链接器之前预期编译器错误。

通过删除 .o 我必须假设 Make 是一次而不是单独传递所有 .d 文件。

于 2013-10-17T02:17:50.100 回答