Visual Studio 代码:C++ 包含路径 [英] Visual Studio Code: C++ include path

查看:51
本文介绍了Visual Studio 代码:C++ 包含路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 https://marketplace.visualstudio.com/items?itemName=mitaki28.vscode-clang 这是一个很好的访问成员函数的小工具.

I'm currently using https://marketplace.visualstudio.com/items?itemName=mitaki28.vscode-clang which is great as a nice little tool for accessing member functions.

但是,我在导入的项目中遇到了一个问题.虽然上述 clang 功能有效,但我在使用包含目录时遇到了特殊问题.我的项目结构如下:

I am however having one issue with a project I am importing. While the above clang feature works, I am having particular problem with using include directories. My project structure is as follows:

|- src/
   |- main.cpp
|- include/
   |- MyHelper.h
|- CMakeLists.txt

有没有办法在 Visual Studio Code 中配置我的包含目录,以便在 main.cpp 中我可以这样做:#include "MyHelper.h" 而不是 #include "include/MyHelper.h"?

Is there a way to configure my include directories in Visual Studio Code such that in main.cpp I can just do: #include "MyHelper.h" instead of #include "include/MyHelper.h"?

在编辑器中,它突出显示了我的包含声明,说它无法找到该文件.虽然编辑器不是什么大问题(我的项目编译),但随后的问题是 vscode-clang 插件无法工作,因为它没有看到文件.

In the editor, it highlights my include statement saying it's unable to find the file. While the editor is not a big deal (my project compiles), the subsequent issue is the vscode-clang plugin does not work because it does not see the file.

也许它甚至可以在编辑器中使用我的 CMakeLists.txt 中的配置来进行必要的包含?

Perhaps even have it use the config from my CMakeLists.txt in the editor for necessary includes?

谢谢!

推荐答案

好吧,这很愚蠢,但如果有人使用 Visual Studio Code 并且没有一个微不足道的项目.这些说明假设您使用的是 clang 编译器:

Okay, this was foolish, but in the event someone uses Visual Studio Code and does not have a trivial project. These instructions are assuming you're using clang compiler:

  1. 打开你的项目目录
  2. 打开.vscode/settings.json
  3. 在 JSON 对象内部配置以下行:

  1. Open your project directory
  2. Open .vscode/settings.json
  3. Configure the line below inside of the JSON object:

// Compiler options for C++ (e.g. ['-std=c++11'])
"clang.cxxflags": [
    "-I/path/to/my/include/directory" // header files
],

这篇关于Visual Studio 代码:C++ 包含路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆