包括其他目录中的头文件

huangapple go评论74阅读模式
英文:

Including header files from other directories

问题

我正在处理一个相当大的dll文件,我不想使用传统的“源文件”和“头文件”布局,因为这样我需要花费很长时间才能找到我要找的文件。相反,我将我的main.c文件从源文件移出,放到了解决方案中的主目录中(我正在使用Visual Studio 2019)。

但是我无法弄清楚如何在Main.c中包含Base.h。我尝试了#include "base/Base.h",但是它给我一个红色的下划线,显示“无法打开源文件”。也许我需要在解决方案的属性中进行一些编辑,但是我已经尝试了一段时间,但无法使其工作。

英文:

I am working on a rather large dll and I dont want to use the convectional Source Files and Header Files layout because it would take me a while to find the file I am looking for. Instead, I moved my main.c file out of Source Files and into the main directory that is housed within my solution (I am using Visual Studio 2019).

包括其他目录中的头文件

But I can't figure out how to include Base.h from within Main.c I tried doing #include "base/Base.h" but that gives me a red underline saying, "cannot open source file". Maybe there is something I have to edit in the properties of my solution, but I have tried for a while now without being able to get this to work.

答案1

得分: 1

您的“base”文件夹不是一个文件夹,而是一个可以用来对您的文件进行排序的过滤器,例如.cpp.hMain.cBase.cBase.h应该都在同一个目录中,这样您就可以使用#include "Base.h"来使其工作。

我建议您创建一个实际的文件夹并切换到“显示所有文件”(在解决方案资源管理器中,顶部有一个类似于三个矩形叠加在一起的按钮)。然后,您可以通过右键单击项目->点击添加->点击新建文件夹来创建一个新文件夹。

包括其他目录中的头文件

包括其他目录中的头文件

英文:

Your "folder" base is not a folder, it is a filter which can be used to sort your files for e.g. .cpp and .h. Main.c, Base.c and Base.h should all be in the same directory so you could just #include "Base.h" for it to work.

I would recommend to create an actual folder and switch to "Show All Files" (in the Solution Explorer in the top the button with like three rectangles above of each other). Then you can just create a new folder with: right clicking the project -> clicking on Add -> clicking on New Folder.

包括其他目录中的头文件

包括其他目录中的头文件

答案2

得分: 0

我尝试使用#include "base/Base.h",但是它给我一个红色下划线,显示"无法打开源文件"。

如果编译成功,那么这个错误就不重要了,应该会消失。可以使用gcc -o Main.c main进行编译。

英文:

> I tried doing #include "base/Base.h" but that gives me a red underline saying, "cannot open source file".

if it compiles then that error doesnt matter and should go away. gcc -o Main.c main

huangapple
  • 本文由 发表于 2023年8月9日 02:35:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76862330.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定