Makefile - 从源生成目标
我正在尝试使用 make 构建越来越多的 .cpp 文件。它们都位于子目录 src/ 中。我想将每个文件编译成它自己的可执行文件,驻留在 bin/ 中。 这是我到目前为止所尝试过的,但它不起作用,而且由于我是新来的,所以所有的模式、变量等都使得很难确定什么被扩展到什么等等。
CXX = g++
CXXFLAGS = -Wall -Wextra -pedantic
SRC = $(wildcard src/*.cpp)
BIN = $(patsubst src/%.cpp,bin/%,$(SRC))
all: $(BIN)
%: scr/%.cpp
$(CXX) $(CXXFLAGS) $< -o $@
另外,有没有办法只显示 BIN 的内容,例如让我看看发生了什么?
I'm trying to build a growing number of .cpp files with the use of make. They all reside in a subdirectory src/. I want to compile each file into it's own executable, residing in bin/.
This is what I have tried so far, but it doesn't work, and since I'm new to make, all the Patterns, Variables etc. make it difficult to pinpoint what gets expanded into what and so on.
CXX = g++
CXXFLAGS = -Wall -Wextra -pedantic
SRC = $(wildcard src/*.cpp)
BIN = $(patsubst src/%.cpp,bin/%,$(SRC))
all: $(BIN)
%: scr/%.cpp
$(CXX) $(CXXFLAGS) lt; -o $@
Also, is there a way to show just the contents of BIN for example to allow me to see what is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是你最终的扩展的样子
为什么不这样做呢?
我认为这有效吗?
至于显示BIN的内容
This is what your final expansion looks like
Why not do this?
I think that works?
As for showing the contents of BIN