视频加载失败

Makefile 与 CMake:构建自动化基础

7959 字
40 分钟
Makefile 与 CMake:构建自动化基础

【一】Makefile#

【1】什么是Makefile#

什么是makefile?或许很多Windows的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序员,makefile还是要懂。

特别在linux下的软件编译,你就不能不自己写makefile了,会不会写makefile,从一个侧面说明了一个人是否具备完成大型工程的能力。

因为,makefile关系到了整个工程的编译规则。一个工程中的源文件不计数,其按类型、功能、模块分别放在若干个目录中,makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为makefile就像一个Shell脚本一样,其中也可以执行操作系统的命令。

makefile带来的好处就是——“自动化编译”,一旦写好,只需要一个make命令,整个工程完全自动编译,极大的提高了软件开发的效率。

关于程序的编译和链接

在此,我想多说关于程序编译的一些规范和方法,一般来说,无论是C、C++,首先要把源文件编译成*中间代码文件,在Windows下也就是 .obj 文件,linux下是 .o 文件,即 Object File,这个动作叫做编译(compile)。然后再把大量的Object File合成执行文件,这个动作叫作链接(link)。

编译时,编译器需要的是语法的正确,函数与变量的声明的正确。对于后者,通常是你需要告诉编译器头文件的所在位置(头文件中应该只是声明,而定义应该放在C/C++文件中),只要所有的语法正确,编译器就可以编译出中间目标文件。一般来说,每个源文件都应该对应于一个中间目标文件(O文件或是OBJ文件)。

链接时,主要是链接函数和全局变量,所以,我们可以使用这些中间目标文件(O文件或是OBJ文件)来链接我们的应用程序。链接器并不管函数所在的源文件,只管函数的中间目标文件(Object File),在大多数时候,由于源文件太多,编译生成的中间目标文件太多,而在链接时需要明显地指出中间目标文件名,这对于编译很不方便,所以,我们要给中间目标文件打个包,静态库通常是 Windows 的 .lib 或 Linux 的 .a;动态库通常是 Windows 的 .dll(配套导入库可能仍为 .lib)或 Linux 的 .so。

【2】Makefile 介绍#

make命令执行时,需要一个 Makefile 文件,以告诉make命令需要怎么样的去编译和链接程序。

首先,我们用一个示例来说明Makefile的书写规则。以便给大家一个感性认识。这个示例来源于GNU的make使用手册,在这个示例中,我们的工程有5个C文件,和4个头文件,我们要写一个Makefile来告诉make命令如何编译和链接这几个文件。

我们的规则是:

  • 如果这个工程没有编译过,那么我们的所有C文件都要编译并被链接。
  • 如果这个工程的某几个C文件被修改,那么我们只编译被修改的C文件,并链接目标程序。
  • 如果这个工程的头文件被改变了,那么我们需要编译引用了这几个头文件的C文件,并链接目标程序。

只要我们的Makefile写得够好,所有的这一切,我们只用一个make命令就可以完成,make命令会自动智能地根据当前的文件修改的情况来确定哪些文件需要重编译,从而自己编译所需要的文件和链接目标程序。

【3】Makefile的规则#

在讲述这个Makefile之前,还是让我们先来粗略地看一看Makefile的规则。

target: prerequisites
command1
...
...

命令行开头必须是 Tab(除非显式修改 .RECIPEPREFIX);把 Tab 写成空格是 Makefile 最常见的格式错误之一。

target也就是一个目标文件,可以是Object File,也可以是执行文件。还可以是一个标签(Label)。

prerequisites就是,要生成那个target所需要的文件或是目标。

command也就是make需要执行的命令。(任意的Shell命令)

这是一个文件的依赖关系,也就是说,target这一个或多个的目标文件依赖于prerequisites中的文件,其生成规则定义在command中。

说白一点就是说,prerequisites中如果有一个以上的文件比target文件要新的话,command所定义的命令就会被执行。这就是Makefile的规则。也就是Makefile中最核心的内容。

【4】编程练习#

题目要求 正如前面所说的,如果一个工程有4个头文件,和5个C文件,我们为了完成前面所述的那三个规则,我们的Makefile应该是下面的这个样子的。

源文件

command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile

源代码main.c

#include <stdio.h>
#include "display.h"
#include "command.h"
#include "insert.h"
#include "kbd.h"
int main(int argc, const char *argv[])
{
display();
display_kbd();
display_command();
display_insert();
printf("hello world!!\n");
return 0;
}

display.h

#ifndef __DISPLAY__
#define __DISPLAY__
int display(void);
#endif

display.c

#include <stdio.h>
int display()
{
printf("display\n");
return 0;
}

kbd.c 与 kbd.h

kbd.c

#include <stdio.h>
int display_kbd()
{
printf("display_kdb\n");
return 0;
}

kbd.h

#ifndef __KDB__
#define __KDB__
int display_kbd(void);
#endif

command.h

#ifndef __COMMAND__
#define __COMMAND__
int display_command(void);
#endif

command.c

#include <stdio.h>
int display_command()
{
printf("display_command\n");
return 0;
}

insert.c

#include <stdio.h>
int display_insert()
{
printf("display_insert\n");
return 0;
}

insert.h

#ifndef __INSERT__
#define __INSERT__
int display_insert(void);
#endif

makefile

main : main.o kbd.o command.o display.o insert.o
cc -o main main.o kbd.o command.o display.o insert.o
main.o: main.c display.h command.h insert.h kbd.h
cc -c main.c # cc -c main.c -o main.o
kbd.o : kbd.c kbd.h
cc -c kbd.c
command.o : command.c command.h
cc -c command.c
display.o : display.c display.h
cc -c display.c
insert.o : insert.c insert.h
cc -c insert.c
.PHONY: clean
clean :
rm -f main main.o kbd.o command.o display.o insert.o

运行结果

Terminal window
linux@ubuntu:~/work/02-makefile/01-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile
linux@ubuntu:~/work/02-makefile/01-exam$ sudo apt install make -y # 安装 make chengxu
Terminal window
linux@ubuntu:~/work/02-makefile/01-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile
linux@ubuntu:~/work/02-makefile/01-exam$ make
cc -c main.c # cc -c main.c -o main.o
cc -c display.c
cc -c command.c
cc -c insert.c
cc -c kbd.c
cc -o main main.o display.o command.o insert.o kbd.o
linux@ubuntu:~/work/02-makefile/01-exam$ ls
command.c command.o display.h insert.c insert.o kbd.h main main.o
command.h display.c display.o insert.h kbd.c kbd.o main.c Makefile
linux@ubuntu:~/work/02-makefile/01-exam$ vi main.c
linux@ubuntu:~/work/02-makefile/01-exam$ make
cc -c main.c # cc -c main.c -o main.o
cc -o main main.o display.o command.o insert.o kbd.o
linux@ubuntu:~/work/02-makefile/01-exam$ ls
command.c command.o display.h insert.c insert.o kbd.h main main.o
command.h display.c display.o insert.h kbd.c kbd.o main.c Makefile
linux@ubuntu:~/work/02-makefile/01-exam$ ./main
display
display_command
display_insert
display_kbd
hello world!!

在这个makefile中,

目标文件(target)包含:执行文件main和中间目标文件(*.o)

依赖文件(prerequisites)就是冒号后面的那些 .c 文件和 .h文件。

每一个 .o 文件都有一组依赖文件,而这些 .o 文件又是执行文件 main 的依赖文件。

在定义好依赖关系后,后续的那一行定义了如何生成目标文件的系统命令,一定要以一个Tab键作为开头。make会比较targets文件和prerequisites文件的修改日期,如果prerequisites文件的日期要比targets文件的日期要新,或者target不存在的话,那么,make就会执行定义的命令。

这里要说明一点的是,clean不是一个文件,它只不过是一个动作名字,其冒号后什么也没有。

【5】make是如何工作的#

在默认的方式下,也就是我们只输入make命令。那么,

  1. make会在当前目录下找名字叫“Makefile”或“makefile”的文件。
  2. 它会找文件中的第一个目标文件(target),在上面的例子中,他会找到“main”这个文件,把这个文件作为最终的目标文件。
  3. 如果main文件不存在,或是main所依赖的后面的 .o 文件的文件修改时间要比main这个文件新,那么,他就会执行后面所定义的命令来生成main这个文件。
  4. 如果main所依赖的.o文件也存在,那么make会在当前文件中找目标为.o文件的依赖性,如果找到则再根据那一个规则生成.o文件。
  5. 当然,你的C文件和H文件是存在的啦,于是make会生成 .o 文件,然后再用 .o 文件声明make的终极任务,也就是执行文件main了。

这就是整个make的依赖性,make会一层又一层地去找文件的依赖关系,直到最终编译出第一个目标文件。

如果依赖文件不存在且没有生成规则,make 会报错。配方中的编译命令返回非零退出码时,make 默认也会停止并报告失败;只有显式使用忽略错误的设置(例如命令前缀 - 或 make -i)才会忽略错误。

通过上述分析,我们知道,像clean这种,没有被第一个目标文件直接或间接关联,那么它后面所定义的命令将不会被自动执行,不过,我们可以显示要make执行。即命令——make clean,以此来清除所有的目标文件,以便重编译。

于是在我们编程中,如果这个工程已被编译过了,当我们修改了其中一个源文件,比如display.c,那么根据我们的依赖性,我们的目标display.o会被重编译(也就是在这个依性关系后面所定义的命令),于是display.o的文件也是最新的啦,于是display.o的文件修改时间要比main要新,所以main也会被重新链接了(重新生成)。

【6】makefile中使用变量#

在上面的例子中,先让我们看看main的规则:

main:main.o display.o command.o insert.o kbd.o
cc -o main main.o display.o command.o insert.o kbd.o
main.o: main.c display.h command.h insert.h kbd.h
.PHONY: clean
clean:
rm -f main main.o display.o command.o insert.o kbd.o

我们可以看到[.o]文件的字符串被重复了两次,如果我们的工程需要加入一个新的[.o]文件,那么我们需要在两个地方加(应该是三个地方,还有一个地方在clean中)。

当然,我们的makefile并不复杂,所以在两个地方加也不累,但如果makefile变得复杂,那么我们就有可能会忘掉一个需要加入的地方,而导致编译失败。

所以,为了makefile的易维护,在makefile中我们可以使用变量。makefile的变量也就是一个字符串,理解成C语言中的宏可能会更好。

比如,我们声明一个变量,叫objects, OBJECTS, objs, OBJS, obj, 或是 OBJ,反正不管什么啦,只要能够表示obj文件就行了。我们在makefile一开始就这样定义:

objects = main.o kbd.o command.o display.o insert.o

于是,我们就可以很方便地在我们的makefile中以$(objects)的方式来使用这个变量了,于是我们的改良版makefile就变成下面这个样子:

objects=main.o kbd.o command.o insert.o display.o
main: $(objects)
cc -o main $(objects)
main.o: main.c display.h command.h insert.h kbd.h
cc -c main.c
kbd.o : kbd.c kbd.h
cc -c kbd.c
command.o : command.c command.h
cc -c command.c
insert.o : insert.c insert.h
cc -c insert.c
display.o : display.c display.h
cc -c display.c
.PHONY: clean
clean:
rm -f main $(objects)

于是如果有新的 .o 文件加入,我们只需简单地修改一下 objects 变量就可以了。

【7】编程练20 - 使用变量#

题目要求 在makefile中使用变量

Terminal window
linux@ubuntu:~/work/02-makefile/02-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile

makefile

objects = main.o display.o command.o insert.o kbd.o
main:$(objects)
cc -o main $(objects)
main.o: main.c display.h command.h insert.h kbd.h
cc -c main.c # cc -c main.c -o main.o
display.o: display.c display.h
cc -c display.c
command.o: command.c command.h
cc -c command.c
insert.o: insert.c insert.h
cc -c insert.c
kbd.o: kbd.c kbd.h
cc -c kbd.c
.PHONY: clean
clean:
rm -f main $(objects)

运行结果

Terminal window
linux@ubuntu:~/work/02-makefile$ cp 01-exam/ 02-exam -a
linux@ubuntu:~/work/02-makefile$ cd 02-exam/
linux@ubuntu:~/work/02-makefile/02-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile
linux@ubuntu:~/work/02-makefile/02-exam$ vi Makefile
linux@ubuntu:~/work/02-makefile/02-exam$ make
cc -c main.c # cc -c main.c -o main.o
cc -c display.c
cc -c command.c
cc -c insert.c
cc -c kbd.c
cc -o main main.o display.o command.o insert.o kbd.o
linux@ubuntu:~/work/02-makefile/02-exam$ ./main
display
display_command
display_insert
display_kbd
hello world!!
linux@ubuntu:~/work/02-makefile/02-exam$ make clean
rm -rf main main.o display.o command.o insert.o kbd.o
linux@ubuntu:~/work/02-makefile/02-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile
linux@ubuntu:~/work/02-makefile/02-exam$

【8】让make自动推导#

GNU的make很强大,它可以自动推导文件以及文件依赖关系后面的命令,于是我们就没必要去在每一个[.o]文件后都写上类似的命令,因为,我们的make会自动识别,并自己推导命令。

只要make看到一个[.o]文件,它就会自动的把[.c]文件加在依赖关系中,如果make找到一个whatever.o,那么whatever.c,就会是whatever.o的依赖文件。并且 cc -c whatever.c 也会被推导出来

于是,我们的makefile再也不用写得这么复杂。我们的是新的makefile又出炉了。

objects=main.o kbd.o command.o insert.o display.o
main: $(objects)
kbd.o : kbd.h
command.o : command.h
insert.o : insert.h
display.o : display.h
.PHONY : clean
main.o: main.c display.h command.h insert.h kbd.h
clean:
rm -f main $(objects)

原始运行记录(具体版本与输出以本机为准):

linux@ubuntu:~/work/02-makefile/03-exam$ make
cc -c -o main.o main.c
cc -c -o kbd.o kbd.c
cc -c -o command.o command.c
cc -c -o insert.o insert.c
cc -c -o display.o display.c
cc main.o kbd.o command.o insert.o display.o -o main
linux@ubuntu:~/work/02-makefile/03-exam$

这种方法,也就是make的“隐晦规则”。上面文件内容中,“.PHONY”表示,clean是个伪目标文件。

【9】编程练习-自动推导#

题目要求 让makefile自动推导 源文件

Terminal window
linux@ubuntu:~/work/02-makefile/03-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile

源代码 Makefile

objects = main.o display.o command.o insert.o kbd.o
main:$(objects)
cc -o main $(objects)
display.o :display.h
command.o :command.h
insert.o :insert.h
kbd.o :kbd.h
main.o: main.c display.h command.h insert.h kbd.h
.PHONY: clean
clean:
rm -f main $(objects)

运行结果

Terminal window
linux@ubuntu:~/work/02-makefile/03-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile
linux@ubuntu:~/work/02-makefile/03-exam$ make
cc -c -o main.o main.c
cc -c -o display.o display.c
cc -c -o command.o command.c
cc -c -o insert.o insert.c
cc -c -o kbd.o kbd.c
cc -o main main.o display.o command.o insert.o kbd.o
linux@ubuntu:~/work/02-makefile/03-exam$ ./main
display
display_command
display_insert
display_kbd
hello world!!
linux@ubuntu:~/work/02-makefile/03-exam$ make clean
rm -rf main main.o display.o command.o insert.o kbd.o

【10】另类风格的makefile#

即然我们的make可以自动推导命令,那么我看到那堆[.o]和[.h]的依赖就有点不爽,那么多的重复的[.h],能不能把其收拢起来,好吧,没有问题,这个对于make来说很容易,谁叫它提供了自动推导命令和文件的功能呢?

来看看最新风格的makefile吧。

objects=main.o kbd.o command.o insert.o display.o
main: $(objects)
.PHONY : clean
main.o: main.c display.h command.h insert.h kbd.h
clean:
rm -f main $(objects)

原始运行记录(具体版本与输出以本机为准):

linux@ubuntu:~/work/02-makefile/04-exam$ make
cc -c -o main.o main.c
cc -c -o kbd.o kbd.c
cc -c -o command.o command.c
cc -c -o insert.o insert.c
cc -c -o display.o display.c
cc main.o kbd.o command.o insert.o display.o -o main
linux@ubuntu:~/work/02-makefile/04-exam$

这种风格,让我们的makefile变得很简单,但我们的文件依赖关系就显得有点凌乱了。鱼和熊掌不可兼得。还看你的喜好了。我是不喜欢这种风格的,一是文件的依赖关系看不清楚,二是如果文件一多,要加入几个新的.o文件,那就理不清楚了。

【11】编程练习-另类风格#

题目要求 另类风格makefile 源文件

Terminal window
linux@ubuntu:~/work/02-makefile/04-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile

源代码 Makefile

objects = main.o display.o command.o insert.o kbd.o
main:$(objects)
cc -o main $(objects)
.PHONY : clean
main.o: main.c display.h command.h insert.h kbd.h
clean:
rm -f main $(objects)

运行结果

Terminal window
linux@ubuntu:~/work/02-makefile/04-exam$ ls
command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c Makefile
linux@ubuntu:~/work/02-makefile/04-exam$ vi Makefile
linux@ubuntu:~/work/02-makefile/04-exam$ make
cc -c -o main.o main.c
cc -c -o display.o display.c
cc -c -o command.o command.c
cc -c -o insert.o insert.c
cc -c -o kbd.o kbd.c
cc -o main main.o display.o command.o insert.o kbd.o
linux@ubuntu:~/work/02-makefile/04-exam$ ./main
display
display_command
display_insert
display_kbd
hello world!!
linux@ubuntu:~/work/02-makefile/04-exam$ make clean
rm -rf main main.o display.o command.o insert.o kbd.o

【12】清空目标文件的规则#

每个Makefile中都应该写一个清空目标文件(.o和执行文件)的规则,这不仅便于重编译,也很利于保持文件的清洁。这是一个“修养”。 一般的风格都是:

clean:
rm -f main $(objects)

更为稳健的做法是:

.PHONY : clean
clean:
rm -f main $(objects)

.PHONY 声明 clean 是伪目标,避免同名文件阻止清理。这里用 rm -f 删除生成的普通文件;-f 会忽略不存在的文件,但不能让 make 忽略所有命令错误。

当然,clean的规则不要放在文件的开头,不然,这就会变成make的默认目标,相信谁也不愿意这样。不成文的规矩是——“clean从来都是放在文件的最后”。

【13】要深入的了解makefile工作原理#

请参考一篇blog (绝对经典,所有问题看这一篇足够了)

【二】CMake#

【1】CMake的介绍#

CMake:CMake的介绍(图 1)
CMake:CMake的介绍(图 1)

CMake 是开源、跨平台的构建系统生成器。它读取 CMakeLists.txt,可生成 Makefile、Ninja、IDE 工程等不同后端;配置可以跨平台复用,但仍需根据编译器、依赖库和平台差异进行适配。

本文主要讲述在Linux下如何使用CMake来编译我们的程序。

【2】安装CMake#

本文使用ubuntu22.04,安装cmake使用如下命令,

Terminal window
sudo apt install cmake
安装完成后,使用 `cmake --version` 查看版本。
linux@ubuntu:~/work/03-cmake/01-exam$ sudo apt install cmake -y # -y 是默认选择y
linux@ubuntu:~/work/03-cmake/01-exam$ cmake --version
cmake version 3.10.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).

(1)编程练习:编写 CMakeLists.txt#

首先让我们从最简单的代码入手,先来体验下cmake是如何操作的。使用Makefile中的例子,在main.c相同目录下编写CMakeLists.txt

main.c:

#include <stdio.h>
int main(void)
{
printf("hello world!!\n");
return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(demo C)
add_executable(main main.c)

第一行声明项目所需的最低 CMake 版本;应根据项目实际使用的 CMake 特性确定,不要仅为了兼容而随意写得过低。

第二行声明工程名和语言。这里明确写 C,所以只检测 C 编译器,不会因为未安装 C++ 编译器而报错;若项目同时使用 C++,可写 project(demo C CXX)。

第三行比较关键,表示最终要生成的可执行文件名为 main,使用的源文件是 main.c。

推荐使用源码外构建,避免在源码目录生成 CMakeCache.txt、CMakeFiles/ 和后端构建文件:

Terminal window
cmake -S . -B build
cmake --build build
./build/main

下面保留的输出记录来自早期的源码内构建与 project(demo) 配置,仅用于识别问题;使用上面的 project(demo C) 不应要求安装 C++ 编译器。

linux@ubuntu:~/work/03-cmake/01-exam$ cmake . # 历史写法:在源码目录生成构建文件
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:3 (project): # 错误信息 , 文件的第三行
No CMAKE_CXX_COMPILER could be found. # 没有c++ 的编译器, 需要安装
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/linux/work/03-cmake/01-exam/CMakeFiles/CMakeOutput.log".
See also "/home/linux/work/03-cmake/01-exam/CMakeFiles/CMakeError.log".
linux@ubuntu:~/work/03-cmake/01-exam$
linux@ubuntu:~/work/03-cmake/01-exam$ sudo apt install g++ # 安装c++ 编译器
linux@ubuntu:~/work/03-cmake/01-exam$ cmake . # 再次运行程序
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/linux/work/03-cmake/01-exam
linux@ubuntu:~/work/03-cmake/01-exam$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake CMakeLists.txt main.c Makefile
linux@ubuntu:~/work/03-cmake/01-exam$ vi Makefile
linux@ubuntu:~/work/03-cmake/01-exam$ make
Scanning dependencies of target main
[ 50%] Building C object CMakeFiles/main.dir/main.c.o
[100%] Linking C executable main
[100%] Built target main
linux@ubuntu:~/work/03-cmake/01-exam$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake CMakeLists.txt main main.c Makefile
linux@ubuntu:~/work/03-cmake/01-exam$ ./main
hello world!!
linux@ubuntu:~/work/03-cmake/01-exam$ make clean
linux@ubuntu:~/work/03-cmake/01-exam$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake CMakeLists.txt main.c Makefile
linux@ubuntu:~/work/03-cmake/01-exam$ make
[ 50%] Building C object CMakeFiles/main.dir/main.c.o
[100%] Linking C executable main
[100%] Built target main

再来看看目录下的文件,可以看到成功生成了Makefile,还有一些cmake运行时自动生成的文件。

然后在终端下输入make并回车,可以看到执行cmake生成的Makefile可以显示进度,并带颜色。再看下目录下的文件,可以看到我们需要的elf文件main也成功生成了,然后运行main,运行成功!

若使用构建目录,可运行 cmake --build build --target clean 清理构建产物;完全重新配置时可删除确认无误的 build 目录后再次执行 cmake -S . -B build。不要在源码目录中随意删除文件。

【3】CMakeCache.txt 引发的错误#

在使用cmake . 的时候, 出现了错误 , 提示如下:

Terminal window
linux@ubuntu:~/work/03-cmake/02-exam$ cmake .
CMake Error: The current CMakeCache.txt directory /home/linux/work/03-cmake/02-exam/
CMakeCache.txt is different than the directory /home/linux/work/03-cmake/01-exam where
CMakeCache.txt was created. This may result in binaries being created in the wrong place.
If you are not sure, reedit the CMakeCache.txt
linux@ubuntu:~/work/03-cmake/02-exam$ ls
cmake并没有提供类似于
cmake --build build --target clean

这样的方式来清除构建产物;CMake 的配置缓存通常位于构建目录中的 CMakeCache.txt 和 CMakeFiles/。因此应坚持源码外构建,避免缓存散落在源码目录。

解决方法:在上一级目录下建立一个build目录,然后在build目录中编译即可。

(2)编程练习:CMakeCache.txt 错误解决#

题目要求 CMakeCache.txt 错误解决

Terminal window
linux@ubuntu:~/work/03-cmake/02-exam$ ls
CMakeLists.txt main.c
linux@ubuntu:~/work/03-cmake/02-exam$ ls
CMakeLists.txt main.c
linux@ubuntu:~/work/03-cmake/02-exam$ mkdir build
linux@ubuntu:~/work/03-cmake/02-exam$ cd build/
linux@ubuntu:~/work/03-cmake/02-exam$ tree
Command 'tree' not found, but can be installed with:
sudo snap install tree # version 1.8.0+pkg-3fd6, or
sudo apt install tree
See 'snap info tree' for additional versions.
linux@ubuntu:~/work/03-cmake/02-exam$ sudo apt install tree
linux@ubuntu:~/work/03-cmake/02-exam/build$ tree ..
..
├── build
├── CMakeLists.txt
└── main.c
1 directory, 2 files
linux@ubuntu:~/work/03-cmake/02-exam/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/linux/work/03-cmake/02-exam/build
linux@ubuntu:~/work/03-cmake/02-exam/build$ make
Scanning dependencies of target main
[ 50%] Building C object CMakeFiles/main.dir/main.c.o
[100%] Linking C executable main
[100%] Built target main
linux@ubuntu:~/work/03-cmake/02-exam/build$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake main Makefile
linux@ubuntu:~/work/03-cmake/02-exam/build$ ./main
hello world!!
linux@ubuntu:~/work/03-cmake/02-exam/build$ tree ..
..
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ │ ├── 3.10.2
│ │ │ ├── CMakeCCompiler.cmake
│ │ │ ├── CMakeCXXCompiler.cmake
│ │ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ ├── CMakeSystem.cmake
│ │ │ ├── CompilerIdC
│ │ │ │ ├── a.out
│ │ │ │ ├── CMakeCCompilerId.c
│ │ │ │ └── tmp
│ │ │ └── CompilerIdCXX
│ │ │ ├── a.out
│ │ │ ├── CMakeCXXCompilerId.cpp
│ │ │ └── tmp
│ │ ├── cmake.check_cache
│ │ ├── CMakeDirectoryInformation.cmake
│ │ ├── CMakeOutput.log
│ │ ├── CMakeTmp
│ │ ├── feature_tests.bin
│ │ ├── feature_tests.c
│ │ ├── feature_tests.cxx
│ │ ├── main.dir
│ │ │ ├── build.make
│ │ │ ├── C.includecache
│ │ │ ├── cmake_clean.cmake
│ │ │ ├── DependInfo.cmake
│ │ │ ├── depend.internal
│ │ │ ├── depend.make
│ │ │ ├── flags.make
│ │ │ ├── link.txt
│ │ │ ├── main.c.o
│ │ │ └── progress.make
│ │ ├── Makefile2
│ │ ├── Makefile.cmake
│ │ ├── progress.marks
│ │ └── TargetDirectories.txt
│ ├── cmake_install.cmake
│ ├── main
│ └── Makefile
├── CMakeLists.txt
└── main.c
9 directories, 35 files

【4】同一目录下多个源文件#

接下来进入稍微复杂的例子:在同一个目录下有多个源文件。

在之前的目录下添加2个文件,display.c和display.h。添加完后整体文件结构如下

Terminal window
display.c , display.h , main.c , CMakeLists.txt

修改CMakeLists.txt,在add_executable的参数里把display.c加进来,然后重新执行cmake生成Makefile并运行make,然后运行重新生成的elf文件main,可以类推,如果在同一目录下有多个源文件,那么只要在add_executable里把所有源文件都添加进去就可以了。

当源文件很多时,CMake 提供 aux_source_directory(<dir> <var>) 收集目录中的源文件。它便于教学和快速原型,但生产工程通常不建议使用:新增/删除源文件后,构建系统未必能自动感知,源文件列表也不清晰。更推荐在 add_executable()、add_library() 中显式列出源文件,或按目录拆分为多个 target。

  • 一个参数dir是指定目录,
  • 第二个参数var是用于存放源文件列表的变量。

(3)编程练习:多文件#

题目要求

aux_source_directory实现自动获取源文件

我们在main.c所在目录下再添加4个文件。添加完后整体文件结构如下:

Terminal window
linux@ubuntu:~/work/03-cmake/03-exam$ ls
CMakeLists.txt command.c command.h display.c display.h insert.c insert.h main.c

CMakeLists.txt

cmake_minimum_required (VERSION 3.22)
project (demo)
aux_source_directory(. SRC_LIST)
add_executable(main ${SRC_LIST})
Terminal window
linux@ubuntu:~/work/03-cmake/03-exam$ cp ../../02-makefile/01-exam/* . -v
'../../02-makefile/01-exam/command.c' -> './command.c'
'../../02-makefile/01-exam/command.h' -> './command.h'
'../../02-makefile/01-exam/display.c' -> './display.c'
'../../02-makefile/01-exam/display.h' -> './display.h'
'../../02-makefile/01-exam/insert.c' -> './insert.c'
'../../02-makefile/01-exam/insert.h' -> './insert.h'
'../../02-makefile/01-exam/kbd.c' -> './kbd.c'
'../../02-makefile/01-exam/kbd.h' -> './kbd.h'
'../../02-makefile/01-exam/main.c' -> './main.c'
'../../02-makefile/01-exam/Makefile' -> './Makefile'
linux@ubuntu:~/work/03-cmake/03-exam$ ls
build CMakeLists.txt command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h
main.c Makefile
linux@ubuntu:~/work/03-cmake/03-exam$ rm Makefile
linux@ubuntu:~/work/03-cmake/03-exam$ ls
build CMakeLists.txt command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c
linux@ubuntu:~/work/03-cmake/03-exam$ cd build/
linux@ubuntu:~/work/03-cmake/03-exam/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/linux/work/03-cmake/03-exam/build
linux@ubuntu:~/work/03-cmake/03-exam/build$ make
Scanning dependencies of target main
[ 16%] Building C object CMakeFiles/main.dir/command.c.o
[ 33%] Building C object CMakeFiles/main.dir/display.c.o
[ 50%] Building C object CMakeFiles/main.dir/insert.c.o
[ 66%] Building C object CMakeFiles/main.dir/kbd.c.o
[ 83%] Building C object CMakeFiles/main.dir/main.c.o
[100%] Linking C executable main
[100%] Built target main
linux@ubuntu:~/work/03-cmake/03-exam/build$ ./main
display
display_command
display_insert
display_kbd
hello world!!
linux@ubuntu:~/work/03-cmake/03-exam/build$

使用aux_source_directory把当前目录下的源文件存列表存放到变量SRC_LIST里,然后在add_executable里调用SRC_LIST(注意调用变量时的写法)。再次执行cmake和make,并运行main,可以看到运行成功了。

【5】不同目录下多个源文件#

一般来说,当程序文件比较多时,我们会进行分类管理,把代码根据功能放在不同的目录下,这样方便查找。那么这种情况下如何编写CMakeLists.txt呢?

(4)编程练习:多目录多文件#

Terminal window
linux@ubuntu:~/work/03-cmake/04-exam$ tree
.
├── bsp
│ ├── insert.c
│ └── insert.h
├── build
├── CMakeLists.txt
├── common
│ ├── command.c
│ ├── command.h
│ ├── display.c
│ ├── display.h
└── main.c
3 directories, 8 files

CMakeLists.txt

cmake_minimum_required (VERSION 3.16)
project(demo)
include_directories(. bsp common)
aux_source_directory(. SRC_LIST1)
aux_source_directory(bsp SRC_LIST2)
aux_source_directory(common SRC_LIST3)
add_executable(main ${SRC_LIST1} ${SRC_LIST2} ${SRC_LIST3})
Terminal window
linux@ubuntu:~/work/03-cmake$ cp 03-exam/ 04-exam -a
linux@ubuntu:~/work/03-cmake$ cd 04-exam/
linux@ubuntu:~/work/03-cmake/04-exam$ ls
build CMakeLists.txt command.c command.h display.c display.h insert.c insert.h kbd.c kbd.h main.c
linux@ubuntu:~/work/03-cmake/04-exam$ rm -rf build/*
linux@ubuntu:~/work/03-cmake/04-exam$ mkdir bsp
linux@ubuntu:~/work/03-cmake/04-exam$ mkdir common
linux@ubuntu:~/work/03-cmake/04-exam$ mv insert.c insert.h bsp
linux@ubuntu:~/work/03-cmake/04-exam$ mv display.* kbd.* command.* common
linux@ubuntu:~/work/03-cmake/04-exam$ ls
bsp build CMakeLists.txt common main.c
linux@ubuntu:~/work/03-cmake/04-exam$ tree
.
├── bsp
│ ├── insert.c
│ └── insert.h
├── build
├── CMakeLists.txt
├── common
│ ├── command.c
│ ├── command.h
│ ├── display.c
│ ├── display.h
│ ├── kbd.c
│ └── kbd.h
└── main.c
3 directories, 10 files
linux@ubuntu:~/work/03-cmake/04-exam$ vi CMakeLists.txt
linux@ubuntu:~/work/03-cmake/04-exam$ cd build/
linux@ubuntu:~/work/03-cmake/04-exam/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/linux/work/03-cmake/04-exam/build
linux@ubuntu:~/work/03-cmake/04-exam/build$ make
Scanning dependencies of target main
[ 16%] Building C object CMakeFiles/main.dir/main.c.o
[ 33%] Building C object CMakeFiles/main.dir/bsp/insert.c.o
[ 50%] Building C object CMakeFiles/main.dir/common/command.c.o
[ 66%] Building C object CMakeFiles/main.dir/common/display.c.o
[ 83%] Building C object CMakeFiles/main.dir/common/kbd.c.o
[100%] Linking C executable main
[100%] Built target main
linux@ubuntu:~/work/03-cmake/04-exam/build$ ./main
display
display_command
display_insert
display_kbd
hello world!!

这里出现了 include_directories(),它为当前目录及其后续子目录添加头文件搜索路径。现代 CMake 更推荐使用目标级的 target_include_directories(main PRIVATE ...),以避免目录级设置意外影响其他 target。

如果没有这个命令来指定头文件所在位置,就会无法编译。

【6】正规一点的组织结构#

正规一点来说,一般会把源文件放到src目录下 ,生成的对象文件放入到build目录下,最终输出的elf文件会放到bin目录下,这样整个结构更加清晰。

让我们把前面的文件再次重新组织下:

Terminal window
linux@ubuntu:~/work/03-cmake/05-exam$ tree
.
├── bin
├── build
├── CMakeLists.txt
└── src
├── bsp
│ ├── insert.c
│ └── insert.h
├── common
│ ├── command.c
│ ├── command.h
│ ├── display.c
│ └── display.h
└── main.c
5 directories, 8 files
linux@ubuntu:~/work/03-cmake/05-exam$
我们在最外层目录下新建一个CMakeLists.txt,内容如下:
cmake_minimum_required (VERSION 3.16)
project (demo)
add_subdirectory (src)

这里出现一个新的命令add_subdirectory(),这个命令可以向当前工程添加存放源文件的子目录,并可以指定中间二进制和目标二进制的存放位置。

这里指定src目录下存放了源文件,当执行cmake时,就会进入src目录下去找src目录下的CMakeLists.txt,所以在src目录下也建立一个CMakeLists.txt,内容如下:

aux_source_directory(. SRC_LIST)
aux_source_directory(bsp BSP_SOURCES)
aux_source_directory(common COMMON_SOURCES)
add_executable(main ${SRC_LIST} ${BSP_SOURCES} ${COMMON_SOURCES})
target_include_directories(main PRIVATE . bsp common)
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

这里又出现一个新的命令set,是用于定义变量的,EXECUTABLE_OUT_PATH和PROJECT_SOURCE_DIR是CMake自带的预定义变量

其意义如下,

EXECUTABLE_OUTPUT_PATH :可执行文件的存放位置

PROJECT_SOURCE_DIR:工程的根目录

所以,这里set的意思是把存放elf文件的位置设置为工程根目录下的bin目录。

(5)编程练习:正规的写法#

题目要求

使用正规的写法规划工程。

Terminal window
linux@ubuntu:~/work/03-cmake/05-exam$ tree
.
├── bin
├── build
├── CMakeLists.txt
└── src
├── bsp
│ ├── insert.c
│ └── insert.h
├── CMakeLists.txt
├── common
│ ├── command.c
│ ├── command.h
│ ├── display.c
│ ├── display.h
└── main.c
5 directories, 11 files

CMakeLists.txt

cmake_minimum_required (VERSION 3.16)
project(demo)
add_subdirectory (src)

src/CMakeLists.txt

include_directories(. bsp common)
aux_source_directory(. SRC_LIST1)
aux_source_directory(bsp SRC_LIST2)
aux_source_directory(common SRC_LIST3)
add_executable(main ${SRC_LIST1} ${SRC_LIST2} ${SRC_LIST3})
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
Terminal window
linux@ubuntu:~/work/03-cmake/04-exam$ cd ..
linux@ubuntu:~/work/03-cmake$ cp 04-exam/ 05-exam -a
linux@ubuntu:~/work/03-cmake$ cd 05-exam/
linux@ubuntu:~/work/03-cmake/05-exam$ ls
bsp build CMakeLists.txt common main.c
linux@ubuntu:~/work/03-cmake/05-exam$ mkdir bin
linux@ubuntu:~/work/03-cmake/05-exam$ mkdir src
linux@ubuntu:~/work/03-cmake/05-exam$ mv bsp/ src
linux@ubuntu:~/work/03-cmake/05-exam$ mv common/ src
linux@ubuntu:~/work/03-cmake/05-exam$ mv main.c src
linux@ubuntu:~/work/03-cmake/05-exam$ cp CMakeLists.txt src/
linux@ubuntu:~/work/03-cmake/05-exam$ rm -rf build/*
linux@ubuntu:~/work/03-cmake/05-exam$ tree
.
├── bin
├── build
├── CMakeLists.txt
└── src
├── bsp
│ ├── insert.c
│ └── insert.h
├── CMakeLists.txt
├── common
│ ├── command.c
│ ├── command.h
│ ├── display.c
│ ├── display.h
│ ├── kbd.c
│ └── kbd.h
└── main.c
5 directories, 11 files
linux@ubuntu:~/work/03-cmake/05-exam$ cd build/
linux@ubuntu:~/work/03-cmake/05-exam/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/linux/work/03-cmake/05-exam/build
linux@ubuntu:~/work/03-cmake/05-exam/build$ make
[ 16%] Building C object src/CMakeFiles/main.dir/main.c.o
[ 33%] Building C object src/CMakeFiles/main.dir/bsp/insert.c.o
[ 50%] Building C object src/CMakeFiles/main.dir/common/command.c.o
[ 66%] Building C object src/CMakeFiles/main.dir/common/display.c.o
[ 83%] Building C object src/CMakeFiles/main.dir/common/kbd.c.o
[100%] Linking C executable ../../bin/main
[100%] Built target main
linux@ubuntu:~/work/03-cmake/05-exam/build$ ls ../bin/
main
linux@ubuntu:~/work/03-cmake/05-exam/build$ ../bin/main
display
display_command
display_insert
display_kbd
hello world!!
linux@ubuntu:~/work/03-cmake/05-exam/build$ make clean
linux@ubuntu:~/work/03-cmake/05-exam/build$ ls ../bin/

【7】另外一种写法#

前面的工程使用了2个CMakeLists.txt,最外层的CMakeLists.txt用于掌控全局,使用add_subdirectory来控制其它目录下的CMakeLists.txt的运行。

上面的例子也可以只使用一个CMakeLists.txt,把最外层的CMakeLists.txt内容改成如下,

cmake_minimum_required (VERSION 3.16)
project (demo)
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
aux_source_directory(src SRC_LIST)
aux_source_directory(src/bsp BSP_SOURCES)
aux_source_directory(src/common COMMON_SOURCES)
add_executable(main ${SRC_LIST} ${BSP_SOURCES} ${COMMON_SOURCES})
target_include_directories(main PRIVATE src src/bsp src/common)

同时,还要把src目录下的CMakeLists.txt删除。

(6)编程练习:另外一种写法#

Terminal window
linux@ubuntu:~/work/03-cmake/06-exam$ tree
.
├── bin
├── build
├── CMakeLists.txt
└── src
├── bsp
│ ├── insert.c
│ └── insert.h
├── common
│ ├── command.c
│ ├── command.h
│ ├── display.c
│ ├── display.h
└── main.c
5 directories, 10 files

CMakeLists.txt

cmake_minimum_required (VERSION 3.16)
project(demo)
include_directories(src src/bsp src/common)
aux_source_directory (src SRC_LIST1)
aux_source_directory (src/bsp SRC_LIST2)
aux_source_directory (src/common SRC_LIST3)
add_executable (main ${SRC_LIST1} ${SRC_LIST2} ${SRC_LIST3})
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
Terminal window
linux@ubuntu:~/work/03-cmake$ cp 05-exam/ 06-exam -a
linux@ubuntu:~/work/03-cmake$ cd 06-exam/
linux@ubuntu:~/work/03-cmake/06-exam$ rm -rf build/*
linux@ubuntu:~/work/03-cmake/06-exam$ rm -rf bin/main
linux@ubuntu:~/work/03-cmake/06-exam$ rm src/CMakeLists.txt
linux@ubuntu:~/work/03-cmake/06-exam$ tree
.
├── bin
├── build
├── CMakeLists.txt
└── src
├── bsp
│ ├── insert.c
│ └── insert.h
├── common
│ ├── command.c
│ ├── command.h
│ ├── display.c
│ ├── display.h
│ ├── kbd.c
│ └── kbd.h
└── main.c
5 directories, 10 files
linux@ubuntu:~/work/03-cmake/06-exam$ cd build/
linux@ubuntu:~/work/03-cmake/06-exam/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/linux/work/03-cmake/06-exam/build
linux@ubuntu:~/work/03-cmake/06-exam/build$ make
Scanning dependencies of target main
[ 16%] Building C object CMakeFiles/main.dir/src/bsp/insert.c.o
[ 33%] Building C object CMakeFiles/main.dir/src/common/command.c.o
[ 50%] Building C object CMakeFiles/main.dir/src/common/display.c.o
[ 66%] Building C object CMakeFiles/main.dir/src/common/kbd.c.o
[ 83%] Linking C executable ../bin/main
[100%] Built target main
linux@ubuntu:~/work/03-cmake/06-exam/build$ ../bin/main
display
display_command
display_insert
display_kbd
hello world!!
linux@ubuntu:~/work/03-cmake/06-exam/build$ make clean
linux@ubuntu:~/work/03-cmake/06-exam/build$ ls ../bin/

【补充】验证与故障排查#

先用 make -n 查看将执行的命令,再构建;修改被包含的头文件后再次执行 make,确认对应目标重新编译。遇到 missing separator 检查配方行首是否为 Tab。CMake 推荐 cmake -S . -B build、cmake --build build;移动工程或更换生成器时使用新的构建目录,避免复用旧缓存。文中的旧终端记录用于说明流程,版本与逐行输出可能不同。

参考资料#

GNU make 规则;make 错误处理;CMake 官方教程。

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

打赏
Makefile 与 CMake:构建自动化基础
https://firefly.cuteleaf.cn/posts/circuit-design/linux/1-base-system/150makefile与cmake/
作者
Dream
发布于
2026-03-05
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
Dream
Hello, I'm Dream.
公告
欢迎来到我的博客!爱学习爱进步。
分类
标签
最新动态
站点统计
文章
367
分类
6
标签
201
总字数
804,820
运行时长
0 天
最后活动
0 天前
站点信息
构建平台
Vercel
博客版本
Firefly v6.16.8
文章许可
CC BY-NC-SA 4.0
文章目录