VSCode C++开发环境设置-更多C/C++配置, 重点在于通过c_cpp_properties.json文件提供更多控制。
- 请先阅读VSCode C++开发环境设置-构建及运行 macOS版和VSCode C++开发环境设置-调试 macOS版, 本文在其基础上进行说明。
步骤
-
可以创建c_cpp_properties.json文件提供更多的C/C++扩展控制。例如改变编译器路径、包含路径、C++标准等。
-
按⇧⌘P,在出现的下拉框中选择C/C++: Edit Configurations (UI) 或 C/C++: Edit Configurations (JSON) ,一个是界面操作,一个是json文件操作
-
当前目录结构如下:
helloworld |- .vscode |- tasks.json |- launch.json |- c_cpp_properties.json // C/C++配置文件 |- helloworld.cpp
-
c_cpp_properties.json文件内容如下:
{ "configurations": [ { "name": "Mac", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "macFrameworkPath": [ "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" ], "compilerPath": "/usr/bin/clang", "cStandard": "c11", "cppStandard": "c++98", "intelliSenseMode": "macos-clang-x64" } ], "version": 4 }
-
c_cpp_properties.json解释
- includePath 包含路径
- Compiler path 编译器路径,用它来推断C++标准库头文件路径,其寻找规则为:
- PATH路径中已知编译器名称,
- 硬编码的Xcode路径:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
- macFrameworkPath 系统头文件路径
-
复用
- 将c_cpp_properties.json拷贝到新的工程目录的.vscode目录中即可