c++ - 如何在子目录中生成带有源代码的 Makefile?

标签 c++ makefile

我通过以下方式找到了源。

/src/main.cpp
/src/hearts/hearts.cpp
/src/spades/spades.cpp
/src/oldmaid/oldmaid.cpp

我将如何为此创建一个 makefile?

最佳答案

我的 Makefile 的摘录。这会在 src 目录中搜索 cpp 文件并编译它们。您可以添加新文件并自动选择它们。

CC = g++  

all: compile
   find src -name '*.o' -print0 | xargs -0 $(CC) -o myExecutable

compile:
    find src -name '*.cpp' -print0 | xargs -0 $(CC) -c

clean:
    find src -iname '*.o' -print0 | xargs -0 rm

关于c++ - 如何在子目录中生成带有源代码的 Makefile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13597051/

相关文章:

c++ - 改变 uniform_int_distribution 的范围

c++ - 多次调用 istream 上的 putback()

c++ - 是否可以在容器中放置 std::array?如果是怎么样?如果不是,为什么?

Makefile 将 child 放在链上

用于编译源文件列表的 Makefile

c - 避免在 makefile 中重复行

c++ - C++中的循环继承

c++ - 减去与同一数组未定义行为无关的两个指针的基本原理是什么?

c - Visual Studio C 编译器是否具有与 GCC 的 -M 等效的功能?

c - Makefile, "nothing to be done for all"错误