gpt4 book ai didi

c++ - 这个 makefile 是如何生成目标文件的?

转载 作者:太空狗 更新时间:2023-10-29 21:16:03 24 4
gpt4 key购买 nike

我有一个简单的问题。我做了一个像这样的简单 Makefile

OBJ = main.o Str.o Out.o
CC = g++
TAR = main

$(TAR):$(OBJ) Header.h
$(CC) -o $(TAR) $(OBJ)

clean:
rm -f $(OBJ) $(TAR)

我的当前目录中只有 Str.cppOut.cppmain.cpp。即使我错过了将源文件转换为目标文件的过程(如 g++ -c Str.cpp),效果很好。

我很好奇为什么这个 Makefile 可以工作。它会自动生成目标文件吗?

最佳答案

10.2 Catalogue of Built-In Rules

Compiling C++ programs

n.o is made automatically from n.cc, n.cpp, or n.C with a recipe of the form ‘$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c’. We encourage you to use the suffix ‘.cc’ for C++ source files instead of ‘.C’.

答案是肯定的,它在同一目录中为每个源文件创建目标文件(然后将它们与您的规则链接到最终可执行文件)。

关于c++ - 这个 makefile 是如何生成目标文件的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36277505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com