yan*_*ang 2 c++ boost visual-studio-code
问题更新: 我正在尝试使用 C/C++ 扩展在 vscode 上构建一个 C++ 项目。编译器抱怨找不到头文件(实际上是 boost 头文件)。我已经包含了 boost 根文件夹的路径,并且 Intellisense 也能够解析头文件路径,但不能解析编译器。我检查了源文件中包含的头文件是否位于文件系统中的相应路径中。有没有办法让编译器看到包含头文件?
这是我的c_cpp_properties.json文件:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Users/zz_ro/Documents/source/boost_1_70_0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/mingw/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Run Code Online (Sandbox Code Playgroud)
这是我的helloworld.cpp文件:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Users/zz_ro/Documents/source/boost_1_70_0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/mingw/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Run Code Online (Sandbox Code Playgroud)
这是编译器输出:
helloworld.cpp:1:46: fatal error: boost/math/constants/constants.hpp: No such file or directory
#include "boost/math/constants/constants.hpp"
^
compilation terminated.
The terminal process terminated with exit code: 1
Run Code Online (Sandbox Code Playgroud)
如果我改变我tasks.json的
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"helloworld.cpp",
"-o",
"helloworld"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
到
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-IC:\\Users\\zz_ro\\Documents\\source\\boost_1_70_0",
"helloworld.cpp",
"-o",
"helloworld"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
只需手动将包含路径作为参数传递给g++.exe,编译就会通过。让我感到困惑的是,在教程(vscode 教程)中没有提到g++.exe通过命令行参数手动插入包含路径,所有这些都应该通过修改c_cpp_property.json. 是我误解了教程还是我没有正确设置 includePath 值?
c_cpp 属性用于智能感知。它不用于编译。编译器在那里只是因为它被查询以找到它用于系统头的默认包含路径。
任务定义了构建任务的运行方式。
vscode 没有将两者联系起来。
| 归档时间: |
|
| 查看次数: |
10574 次 |
| 最近记录: |