(一)CMake使用
CMake使用
1.注释
# 这是一个CMakeLists.txt文件
cmake_minimum_required(VERSION 3.10)
2.add_executable 定义工程会生成一个可执行程序
add_executable(可执行程序名 源文件名称)
# 样式1:
add_executable(app add.c div.c main.c mult.c sub.c)
(二)HelloWorld 项目文章来源:https://www.toymoban.com/news/detail-786157.html
heheda@linux:~/Linux/HelloWorld$ tree
.
├── build
├── CMakeLists.txt
└── helloworld.cpp
1 directory, 2 files
- helloworld.cpp
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
cout<<"Hello World"<<endl;
return 0;
}
- CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(HELLOWORLD)
add_executable(app helloworld.cpp) # g++ helloworld.cpp -o app
- 命令执行
执行命令:
1.mkdir build
2.cd build
3.cmake ..
4.make
5./app
执行结果:
heheda@linux:~/Linux/HelloWorld$ cd build
heheda@linux:~/Linux/HelloWorld/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/heheda/Linux/HelloWorld/build
heheda@linux:~/Linux/HelloWorld/build$ make
Scanning dependencies of target app
[ 50%] Building CXX object CMakeFiles/app.dir/helloworld.cpp.o
[100%] Linking CXX executable app
[100%] Built target app
heheda@linux:~/Linux/HelloWorld/build$ ./app
Hello World
heheda@linux:~/Linux/HelloWorld/build$
文章来源地址https://www.toymoban.com/news/detail-786157.html
到了这里,关于CMake HelloWorld的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!