[英]Visual Studio Code - Include Path Problems Header Files C++ (MinGW)
我对 C++ 编程还很陌生,所以请不要在设置“Visual Studio Code”环境时判断我的问题。 我正在尝试使用 blaze 数学包来解决二次规划问题。 使用 MinGW GCC,我可以通过 cmd 成功编译 blaze 的测试文件,因此我想将 GCC 用于 VS Code。
操作系统:Windows 10.0.19041
GCC: gcc (x86_64-posix-seh-rev0, 由 MinGW-W64 项目构建) 7.3.0 || (cmd: gcc --version)
VS 代码扩展:C/C++ 0.27.1
首先,我浏览了 MinGW 的 VS Code 教程: https : //code.visualstudio.com/docs/cpp/config-mingw
这工作得很好,所以我可以轻松地编译我的 helloworld.cpp。 生成的 tasks.json 文件看起来像这样tasks.json 。
作为我的包管理器(用于 blaze 或其他包),我使用 vspkg-git: https ://docs.microsoft.com/en-us/cpp/build/vcpkg?view = msvc-160 因此我在 Windows I 上编程不能使用“integrate”命令将路径添加到包含路径。 所以我必须手动执行此操作。
我的包在具有绝对路径的文件夹中
C:\Users\Johannes\Desktop\Masterthesis\vcpkg\vcpkg\packages
所以我在“c_cpp_propertier.json”文件中添加了路径
{
"configurations": [
{
"name": "GCC",
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"includePath": [
"${workspaceFolder}",
"C:/Users/Johannes/Desktop/Masterthesis/vcpkg/vcpkg/packages/**"
],
"compilerPath": "C:/Program Files/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/bin/g++.exe",
"browse": {
"path": []
}
}
],
"version": 4
}
在文件夹中有几个包,因此我在路径末尾添加了“/**”以启用对头文件的递归搜索。
我的“helloworld.cpp”文件看起来像这样
#include <iostream>
#include <vector>
#include <string>
//#include <blaze/Math.h>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the
C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
我的问题是,当我尝试从这个路径中包含一个头文件时,例如 Math.h Visual Studio 抛出一个错误
blaze/Math.h: No such file or directory
但是当我右键单击包含并单击“转到定义”时,VS Code 会打开该文件。 选项栏和打开的文件。
Log-Diagnostics 提供了该信息。
我想有使用 MinGW 和 VS Code 中的附加包经验的人会非常简单地解决这个问题,但我已经阅读了几乎所有关于这些问题的帖子,但没有找到任何与我匹配的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.