问题描述
请注意,这与名为通用makefile的其他问题不是重复的.
Please note that this is not a duplicate of the other questions named generic makefile.
我已经按照所有有关通用Makefile的其他问题进行了说明,这是我从中得到的代码:
I have followed all of the instructions on other questions about generic makefiles, and this is the code I have come up with from that:
CFLAGS = -c
CC = cc
SOURCES = $(wildcard *.cc)
OBJECTS = $(patsubst %.cc,%.o,%(SOURCES))
EXEC = run
all: build clean
build: $(OBJECTS)
$(CC) $(OBJECTS) -o $(EXEC)
%.o: %.cc
$(CC) $(CFLAGS) $<
clean:
rm *.o
但是,当我在目录中使用名为test.cc
的文件执行make
时,会出现以下跟随错误:
However, when I execute make
with a file called test.cc
in my directory, it gives me the followig error:
cc -o run
cc: error: no input files
*** Error code 1
Stop.
make: stopped in /somewhere
请注意,我使用的是FreeBSD,make
和cc
命令是操作系统随附的命令.
Please note that I am on FreeBSD and the make
and cc
commands are the ones which come with the OS.
推荐答案
线条
SOURCES = $(wildcard *.cc)
OBJECTS = $(patsubst %.cc,%.o,%(SOURCES))
是FreeBSD的make
无法理解的GNU make语法,它具有自己的方言(特别是$(wildcard)
和$(patsubst)
).如果您需要编写可移植到许多系统的makefile,则需要存在gmake并使用GNUmakefile,或者坚持 POSIX的功能.
are GNU make syntax, not understood by FreeBSD's make
, which has its own dialect (specifically $(wildcard)
and $(patsubst)
). If you need to write makefiles portable to many systems, either require gmake to exist and use GNUmakefiles, or stick to the features of POSIX make.
您可以通过以下方式在FreeBSD上安装GNU make(gmake
)
You can install GNU make (gmake
) on FreeBSD with
cd /usr/ports/devel/gmake
make install clean
这篇关于通用Makefile在FreeBSD上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!