Joe*_*e95 5 c++ mingw path include visual-studio-code
我对 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 || (命令:gcc --版本)
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: //learn.microsoft.com/en-us/cpp/build/vcpkg ?view=msvc-160 因此我在 Windows 上编程无法使用“集成”命令将路径添加到包含路径。所以我必须手动执行此操作。
我的包在绝对路径的文件夹中
C:\Users\Johannes\Desktop\Masterthesis\vcpkg\vcpkg\packages
Run Code Online (Sandbox Code Playgroud)
所以我在“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
}
Run Code Online (Sandbox Code Playgroud)
该文件夹中有几个包,因此我在路径末尾添加了“/**”以启用头文件的递归搜索。
我的“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;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我尝试包含此路径中的头文件(例如 Math.h)时,Visual Studio 会抛出错误
blaze/Math.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)
但是,当我右键单击包含并单击“转到定义”时,VS Code 将打开该文件。选项栏和打开的文件。
日志诊断提供了该信息。
我想有 MinGW 经验和 VS Code 中的附加包的人会非常简单地解决这个问题,但我已经阅读了几乎所有关于这些问题的线程,但没有找到任何与我的匹配的内容。
好的,我得到答案了。“c_cpp_properties.json”文件的包含路径仅适用于 IntelliSense。这意味着 Visual Studio Code 将找到此包,并且 IntelliSense 将向您建议路径中的可用标头。这并不意味着编译器可以找到这些路径。因此,您必须将路径添加到“tasks.json”文件中。正如您在上面的“tasks.json”文件的照片中看到的,有一个名为“args”的字段,意思是“参数”。这些是编译器参数。您还必须以格式“-I”、“C:/PathYouWishToAdd”添加路径。这很好用!
归档时间: |
|
查看次数: |
3817 次 |
最近记录: |