在我的计算机中,c_cpp_properties.json文件如下所示,
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\MinGW\bin\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
compilerPath和intelliSenseMode是否正确?
或者compilerPath应该类似于这个
C:MinGWlibgccmingw326.3.0includec++
或
C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
intelliSenseMode是否应为"gcc-x64"、"clang-x64"或"msvc-x64"?
例如,在微软Vs代码网站上,上述代码更改为
{
"configurations": [
{
"name": "Win32",
"defines": [
"_DEBUG",
"UNICODE"
],
"compilerPath": "C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
https://code.visualstudio.com/docs/cpp/config-mingw#_configure-编译器路径
所以主要的问题是我如何确定在compilePath中使用什么感谢
要回答您的问题,在官方的Visual Code文档中,您可以看到编译器路径和intelliSenseMode的设置如下所示。只要确保给出g++.exe
的正确位置即可。
"compilerPath": "C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"intelliSenseMode": "gcc-x64"
如果您有任何问题,请更新您注意到的问题。
compilerPath
和intelliSenseMode
变量用于配置VSCode编辑器,以分别提供编译和IntelliSense服务。
compilerPath
因为VSCode本身并不是一个完整的IDE,所以它没有附带提供编译服务所需的编译器。因此,它需要指向一个有效的C++编译器的方向。这就是compilerPath
变量的用途。测试您提供的路径是否正确很容易。将其复制并粘贴到终端(CMD或PowerShell)中,然后查看结果输出是否如下所示:
PS C:Usersneilb> C:"Program Files"mingw-w64x86_64-8.1.0-posix-seh-rt_v6-rev0mingw64bing++.exe
g++.exe: fatal error: no input files
compilation terminated.
PS C:Usersneilb>
这意味着路径是有效的。如果没有,请定位MinGW(在Windows上提供gcc
和g++
支持的库)的安装位置。如果尚未安装,请执行此操作。
inteliSenseMode
这篇文章向VSCode介绍了格式化代码和提供linting功能时应遵循的C++样式指南。VSCode-cpptools
GitHub页面上列出了此处的完整选项列表。您当前设置的内容应该足够。(clang-x64
)