【发布时间】:2018-11-24 14:55:59
【问题描述】:
我正在编写一个简单的 Makefile,它将遍历 ./src 文件夹中的 .cpp 文件并包含 ./include 文件夹中的文件。但出现“无输入文件”错误。你能帮我设置一下吗?
我有以下目录结构
./src => It has main source file - Application.cpp and other applicationclass files like MyClass.cpp, Adapter.cpp. ...
./include => Include i.e. .h files, which has declarations.
./obj => Where i am expecting to drop .o files
./bin => Directory where i am expecting to drop executable
我尝试使用以下 Makefile,但它给了我“无输入文件”错误。 我正在使用一些第三方库,其中包含文件,这些文件是“包含”文件夹中的子文件夹。
appname := Application
CXX := g++
CXXFLAGS := -Wall -g
srcfiles := $(shell find . -maxdepth 1 -name "*.cpp")
objects := $(patsubst %.cpp, %.o, $(srcfiles))
all: $(appname)
$(appname): $(objects)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(appname) $(objects) $(LDLIBS)
depend: .depend
.depend: $(srcfiles)
rm -f ./.depend
$(CXX) $(CXXFLAGS) -MM $^>>./.depend;
clean:
rm -f $(objects)
dist-clean: clean
rm -f *~ .depend
include .depend
让我知道我做错了什么或更好的方法来编译这个项目。 感谢您在此问题上提供的任何帮助。
【问题讨论】:
-
为您提供一些工作示例。
-
在这里查看涵盖典型案例的makefile。它是为 Fortran 设计的,但可以很容易地转换为基于 C 的项目:owsiak.org/fortran-and-gnu-make