C/C++:VSCode配置C++开发环境【Windows系统】

 一、安装插件

1、安装C/C++插件

2、安装CMake、CMake插件

3、安装其他插件

3.1、Error Lens(错误提示)

 3.2、One Dark Pro(主题插件)

二、代码演示

1、main.c

#include <iostream>

int main()
{
    std::cout << "\nhello world\n" << std::endl;
    return 0;
}

2、CMakeLists.txt

参考CMake官网

 2.1 创建文件 CMakeLists.txt

在CMakeLists.txt文件中添加:

cmake_minimum_required(VERSION 3.10)

# set the project name
project(Tutorial)

# add the executable
add_executable(Tutorial tutorial.cxx)

2.2 Ctrl + P打开配置文件

2.3 VScode的Unable to determine what CMake generator to use问题处理

Unable to determine what CMake generator to use. Please install or configure a preferred generator, or update settings.json, your Kit configuration or PATH variable.

解决方案

  • 检查当前根目录下(即你通过VSCode的打开文件夹功能打开的文件夹)是否存在以“.code-workspace”文件,如果不存在则如下面的操作创建此文件

在这里插入图片描述

然后在弹出来的文件保存管理窗口中直接点“保存”即可。

  • 打开“.code-workspace”文件

在这里插入图片描述

{
	"folders": [
		{
			"path": "."
		}
	],
	"settings": {
		"files.associations": {
			"*.ejs": "html",
			"iostream": "cpp"
		},
		"cmake.generator": "MinGW Makefiles"
		
	}
}

改成这个样子即可(添加了划红线的语句,旨在告诉CMake你要用的generator姓甚名谁)

在这里插入图片描述

"cmake.generator": "MinGW Makefiles"

3、确保你的VScode至少同时拥有以下3个扩展

  1. C/C++
  2. CMake
  3. CMake Tools

4、然后在工具栏点击CMake

[proc] Executing command: C:\Program_Files_AI\gcc\gcc_1221\ucrt64\bin\gcc.exe -v
[main] Configuring folder: Ctest01 
[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=C:\Program_Files_AI\gcc\gcc_1221\ucrt64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\Program_Files_AI\gcc\gcc_1221\ucrt64\bin\g++.exe -Sd:/Workspaces_C++/Ctest01 -Bd:/Workspaces_C++/Ctest01/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 12.2.1
[cmake] -- The CXX compiler identification is GNU 12.2.1
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program_Files_AI/gcc/gcc_1221/ucrt64/bin/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: C:/Program_Files_AI/gcc/gcc_1221/ucrt64/bin/g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: D:/Workspaces_C++/Ctest01/build

三、VSCode窗口作用

1、选择“编译器”

2、编译

VScode的Unable to determine what CMake generator to use问题处理_LYZ832的博客-CSDN博客

[C++入门] 超简单 VSCode C++开发环境搭建_哔哩哔哩_bilibili

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ERROR: Command errored out with exit status 1: command: 'D:\Python\python.exe' 'D:\Python\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\ASUS\AppData\Local\Temp\tmphrctoh63' cwd: C:\Users\ASUS\AppData\Local\Temp\pip-install-bpjr7cw0\opencv-python Complete output (323 lines): -------------------------------------------------------------------------------- -- Trying 'Ninja (Visual Studio 17 2022 x64 v143)' generator -------------------------------- --------------------------- ---------------------- ----------------- ------------ ------- -- Not searching for unused variables given on the command line. CMake Error at CMakeLists.txt:2 (PROJECT): Generator Ninja does not support platform specification, but platform x64 was specified. -- Configuring incomplete, errors occurred! -- ------- ------------ ----------------- ---------------------- --------------------------- -------------------------------- -- Trying 'Ninja (Visual Studio 17 2022 x64 v143)' generator - failure -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- Trying 'Visual Studio 17 2022 x64 v143' generator -------------------------------- --------------------------- ---------------------- ----------------- ------------ ------- -- Not searching for unused variables given on the command line. CMake Error at CMakeLists.txt:2 (PROJECT): Generator Visual Studio 17 2022 could not find any instance of Visual Studio. -- Configuring incomplete, errors occurred!
07-13

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值