gpt4 book ai didi

c++ - 如何向 task.json 添加多个包含路径?

转载 作者:行者123 更新时间:2023-12-04 18:49:23 24 4
gpt4 key购买 nike

我正在尝试调试此存储库:MP-SPDZ , 其中许多 .h , .hpp.cpp文件被放置在不同的文件夹中。此外,在每个 .cpp文件,包括几个头文件。
这里更清楚的是文件树的样子:

  >ProjectTP
>Machines
-mascot-party.cpp
-SPDZ.cpp
-SPDZ.hpp
-Player-Online.cpp
-Player-Online.hpp
-more files ...
>Processor
-Machine.h
-Machine.hpp
-more files ...
>More folders ...
请注意,在某些情况下 .hpp文件被视为 .h文件,而在其他一些情况下,它们被视为 .cpp文件。问题是当我尝试编译项目时,VS Code 找不到 header ,而我将所有包含路径添加到 task.json .
这是我的主要 .cpp文件 (mascot-party.cpp)位于名为 Machines 的文件夹中在根目录中。
#include "Player-Online.hpp"
#include "Math/gfp.hpp"
#include "GC/TinierSecret.h"

int main(int argc, const char** argv)
{
ez::ezOptionParser opt;
return spdz_main<Share<gfp>, Share<gf2n>>(argc, argv, opt);
}
这是 Player-Online.hpp包含在 (mascot-party.cpp) 中(只是为了显示存储库的嵌套程度)
#include "Processor/Machine.h"
#include "Processor/OnlineOptions.h"
#include "Math/Setup.h"
#include "Protocols/Share.h"
#include "Tools/ezOptionParser.h"
#include "Networking/Server.h"

#include <iostream>
#include <map>
#include <string>
#include <stdio.h>
using namespace std;

template<class T, class U>
int spdz_main(int argc, const char** argv, ez::ezOptionParser& opt, bool live_prep_default = true)

...
return 0;
}
这是我的 task.json :
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${workspaceFolder}/Machines/mascot-party.cpp",
//"${workspaceFolder}/Machines/SPDZ.cpp",
"${workspaceFolder}/Tools/*.cpp",
"${workspaceFolder}/Math/*.cpp",
"${workspaceFolder}/OT/*.cpp",
"${workspaceFolder}/Networking/*.cpp",
"${workspaceFolder}/Processor/*.cpp",
"${workspaceFolder}/Protocols/*.cpp",

"${workspaceFolder}/Machines/*.hpp",
"${workspaceFolder}/Tools/*.hpp",
"${workspaceFolder}/Math/*.hpp",
"${workspaceFolder}/OT/*.hpp",
"${workspaceFolder}/Processor/*.hpp",
"${workspaceFolder}/Protocols/*.hpp",

"-Idir",
"${workspaceFolder}/Processor",
"${workspaceFolder}/Tools",
"${workspaceFolder}/Math",
"${workspaceFolder}/OT",
"${workspaceFolder}/Networking",


"-o",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}
还有我的 c_cpp_properties.json :
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
这是编译器错误:
enter image description here
重要提示:当我将绝对路径放在我的 .cpp 文件中时(例如,而不是 #include "Processor/Machine.h" 我放了 #include "/home/user/MP-SPDZ_VSCode/Processor/Machine.h" ),它会找到标题。但是,存储库很大,无法以这种方式修复它。
我尝试了很多不同的配置这么久,但没有结果。任何帮助表示赞赏。谢谢你。

最佳答案

文件 c_cpp_properties.json 可能不是设置 include 的正确位置目录。根据its reference :

includePath An include path is a folder that contains header files(such as #include "myHeaderFile.h") that are included in a sourcefile. Specify a list of paths for the IntelliSense engine to use whilesearching for included header files.


所以很可能这仅用于智能感知。
在我看来,最安全的选择是在编译器命令中指定包含路径,您已经在 task.json 中手动设置了这些路径。 .在属性(property) args尝试添加参数 -Idir然后是包含目录 Processor 的目录的路径:
"args": [
...
"-Idir",
"${fileDirname}/../dir-that-contains-the-Processor-dir
...
]

关于c++ - 如何向 task.json 添加多个包含路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64713294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com