如何使用Cmake
编译C++
项目的示例,参照每个Demo
里的CMakeLists
文件,有具体注释。
编译方法:进入到当前Demo
的build.sh
脚本文件所在目录,执行该脚本即可。以Demo_1
和Demo_8
为例:
# Demo_1
cd Demo_1
sh build.sh
# Demo_8
cd Demo_8/main
sh build.sh
Demo | 示例说明 |
---|---|
Demo_01 | 编译单个文件 |
Demo_02 | 同一目录下引用一个头文件的编译 |
Demo_03 | 同一目录下引用一个头文件和一个源文件 |
Demo_04 | 同一目录下引用多个头文件和源文件的 |
Demo_05 | 仅引用一个子目录 |
Demo_06 | 引用多个子目录 |
Demo_07 | 引用多个子目录,同时引用同一目录下的多个文件 |
Demo_08 | 多级目录项目中,引用其他目录的文件进行编译 |
Demo_09 | 将编译文件和源代码文件区分开。新建build 目录存放相关的编译文件,注意执行build.sh 脚本编译后可执行文件是在Demo_9/main/build 目录下。 |
Demo_10 | 指定可执行文件的生成目录。注意执行build.sh 后与Demo_9 不同的是可执行文件是在Demo_10/main 目录下。 |
Demo_11 | 多级目录项目中,引用外部文件夹代码,同时引用子目录的文件进行编译 |
Demo_12 | 多级目录项目中,引用外部文件夹代码,同时引用子目录以及同一目录下的文件进行编译 |