cmake+vscode自动生成最简单c++代码
可参考:
这里略有不同,首先需要安装配置mingw64
然后测试简单c++代码是否可以运行:
接着安装下面这些插件:
然后打开vscode:
按F1:选择cmake:Quick Start
然后选择GCC11.2.0:
出现下列界面
输入:
选择:Executable:
此时vscode已经自动生成cmake文件和cpp文件:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.0.0)
project(my_cmake_cpp VERSION 0.1.0)
include(CTest)
enable_testing()
add_executable(my_cmake_cpp main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
main.cpp:
#include <iostream>
int main(int, char**) {
std::cout << "Hello, world!\n";
并自动构建:
[variant] Loaded new set of variants
[kit] Successfully loaded 14 kits from C:\Users\eric\AppData\Local\CMakeTools\cmake-tools-kits.json
[proc] Executing command: d:\software\mingw64\bin\x86_64-w64-mingw32-gcc.exe -v
[main] Configuring folder: test
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=d:\software\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=d:\software\mingw64\bin\x86_64-w64-mingw32-g++.exe -Hd:/work/cmake_work/test -Bd:/work/cmake_work/test/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 11.2.0
[cmake] -- The CXX compiler identification is GNU 11.2.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: d:/software/mingw64/bin/x86_64-w64-mingw32-gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: d:/software/mingw64/bin/x86_64-w64-mingw32-g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done