简体   繁体   English

VS Code无法检测到标准C ++库

[英]VS Code unable to detect Standard C++ Libraries

I started using VS Code, and after messing around with it I kind of managed to make it detect Windows and Direct3D SDK's with the c_cpp_properties.json, but I'm failing to make the Standard Library work. 我开始使用VS Code,在弄乱它之后,我设法使它使用c_cpp_properties.json检测Windows和Direct3D SDK,但是我无法使标准库正常工作。 So, if I do: 所以,如果我这样做:

#include <string>
#include <vector>

It throws me an error just like this: 它像这样抛出一个错误:

//Include file not found in include path

I've searched all over the web and didn't find any clue, so here I am! 我搜索了整个网络,但没有找到任何线索,所以我在这里! Strangely enough, if I just create a new .cpp file in an empty window/editor, it works. 奇怪的是,如果我只是在一个窗口/编辑器中创建一个新的.cpp文件,它就可以工作。 But the moment I 'load' the folder that file is in, then it fails. 但是当我“加载”文件所在的文件夹时,它就失败了。 So, this is really driving me crazy. 所以,这真的使我发疯。

I'm using Windows 10, with .NET 4.6.2, the 2015 Visual C++ Redist, and the Windows 10 SDK, all blazing new installs from today. 我正在使用Windows 10,.NET 4.6.2、2015 Visual C ++ Redist和Windows 10 SDK,从今天开始,所有这些都焕然一新。 My ultimate goal is to port a project I made in VS2013 to GNU/Linux, so I'm trying to make things work step by step. 我的最终目标是将我在VS2013中创建的项目移植到GNU / Linux,因此我试图使事情逐步进行。

Thanks a lot beforehand! 非常感谢!

EDIT: Compiling with g++ works just fine, even though VS Code complains. 编辑:即使VS Code抱怨,使用g ++编译也可以。 This is what happens. 这就是发生的情况。

VS Code need to locate the include libraries. VS Code需要找到包含库。

  1. First of all locate where g++ is located. 首先找到g ++的位置。 You mentioned that it works fine. 您提到它工作正常。 It's an .exe file (windows). 这是一个.exe文件(Windows)。 So you may find g++ directory in path settings. 因此,您可以在路径设置中找到g ++目录。 view path variables. 查看路径变量。

  2. Now after getting g++.exe directory you may easily find a file names string in nearby folders or parent folders. 现在,在获取g ++。exe目录之后,您可以轻松地在附近的文件夹或父文件夹中找到文件名字符串 After successfully locating it copy its full path. 成功定位后,复制其完整路径。

  3. Now back in VS Code put cursor over green underline and you should see a bulb. 现在回到VS Code,将光标置于绿色下划线上,您应该看到一个灯泡。 Click it and in the options you will see option Edit "includePath" setting or Update "browse.path" setting . 单击它,然后在选项中,您将看到选项编辑“ includePath”设置更新“ browse.path”设置 Select it and a file will open named c_cpp_properties.json 选择它,将打开一个名为c_cpp_properties.json的文件。

  4. Now in that file locate "name": "win32" . 现在在该文件中找到“名称”:“ win32” In the include path option paste the directory name of string file like this and you are good to go. 在include path选项中,像这样粘贴字符串文件的目录名称,您就可以开始了。

像这样

In vscode go to file>preferences>settings then select edit in settings.json (This can be hard to find, certain settings have this option by them, others do not. There is probably a better way to access this file, but I don't know it) 在vscode中,转到文件>首选项>设置,然后edit in settings.json选择edit in settings.json (这可能很难找到,某些设置具有此选项,而其他则没有。访问此文件可能是更好的方法,但是我不知道不知道)

This will open up the settings.json file, where you can add the line: 这将打开settings.json文件,您可以在其中添加以下行:

    "C_Cpp.default.includePath": ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include"]

(or whatever your include path is) This will add that include path for all projects, or only the current workspace depending on if you open the settings.json file for "User Settings" or for "Workspace Settings" (或任何包含路径),这将为所有项目或仅当前工作空间添加包含路径,具体取决于您是否打开“用户设置”或“工作空间设置”的settings.json文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM