1. 安装cmake
2. 安装cygwin
https://www.jianshu.com/p/9994a65f2905
3. 在vscode中安装CMake Tools插件
https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools
4. 实际操练经验
如果使用CMake quickstart 生成的项目需要 删除 除了 CMakeLists.txt 和 main.cpp 外的所有东西,然后新建build目录,在build目录下执行
build> cmake -G "Unix Makefiles" ../
[打印]
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.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++.exe
-- Check for working CXX compiler: /usr/bin/c++.exe -- 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: /cygdrive/e/tmp/cpp/build
然后在build目录下make
build> make
[打印]
make[1]: 进入目录“/cygdrive/e/tmp/cpp/build”
make[2]: 进入目录“/cygdrive/e/tmp/cpp/build”
Scanning dependencies of target helloworld
make[2]: 离开目录“/cygdrive/e/tmp/cpp/build”
make[2]: 进入目录“/cygdrive/e/tmp/cpp/build”
[ 50%] Building CXX object CMakeFiles/helloworld.dir/main.cpp.o
[100%] Linking CXX executable helloworld.exe
make[2]: 离开目录“/cygdrive/e/tmp/cpp/build”
[100%] Built target helloworld
make[1]: 离开目录“/cygdrive/e/tmp/cpp/build”
测试编译效果
build>helloworld.exe
Hello, world!
网友评论