如何更改子文件夹的#include默认文件路径

发布于 2025-02-01 04:03:43 字数 1006 浏览 1 评论 0原文

上下文:

我在UE4.23中遵循教程,在某一时刻,我们在source/projectName/文件中创建子文件。然后,在.cpp/.h文件内部,我们只是写了#include“ subfolder/file.h”,并被识别。但是,当我自己的项目练习时(在UE4.26中)时,我必须这样做:#include” ../ subfolder/file.h“”从子文件中上升,告诉我,包括路径在文件夹内部的默认值。

这会导致令人讨厌的问题,在这种情况下,虚幻的问题会创建一个类,并假设我们在上部文件夹中启动了路径,从而导致每个新类引起编译错误包括。

问题:

如何更改默认值包含子文件夹文件的路径以从主文件夹启动?

所需结果的示例:将默认路径设置为“ ../ project/source/projectname/“

//thisclass.cpp file inside of "Source/ProjectName/Test/thisclass.cpp"

/* "Source/ProjectName/Framework/" */
#include "Framework/GameState.h" 

/* "Source/ProjectName/Player/" */
#include "Player/CharacterController.h"

//Must enter sub-folders as well, even though it's in the same subfolder
#include "Test/thisclass.h"

副注:

  • 我尝试使用Google解决方案的尝试不断显示用于更改项目位置的结果,而不是更改目录或包括路径。
  • 我很确定这是一个视觉工作室问题,但是我正在使用虚幻的工作室,所以我都标记了这两个。

Context:

I was following a tutorial in UE4.23 and at one point, we create sub-files in the Source/ProjectName/ file. Then, inside of the .cpp/.h files, we simply wrote #include "Subfolder/File.h" and it was recognized. However, when working on my own project to practice (in UE4.26), I have to do this: #include "../Subfolder/File.h" to go up from the subfile, which tells me the include path is defaulting inside of the folder the file is in.

This causes annoying issues where Unreal will create a class and assume we start our path in the upper folder, causing a compile error with every new class until I manually change the include.

Question:

How do I change the default include path of sub-folder files to start from the main folder?

Example of desired result: Setting default path to "../Project/Source/ProjectName/"

//thisclass.cpp file inside of "Source/ProjectName/Test/thisclass.cpp"

/* "Source/ProjectName/Framework/" */
#include "Framework/GameState.h" 

/* "Source/ProjectName/Player/" */
#include "Player/CharacterController.h"

//Must enter sub-folders as well, even though it's in the same subfolder
#include "Test/thisclass.h"

Side Notes:

  • My attempts to google the solution kept showing results for changing the project location, not changing directories or include paths.
  • I'm pretty sure this is a Visual Studio issue, but I'm using it with Unreal, so I tagged both.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天冷不及心凉 2025-02-08 04:03:43

添加 publicCludePaths 到您的 * .build.cs

public class ProjectName: ModuleRules
{
    public ProjectName(ReadOnlyTargetRules Target) : base(Target)
    {
        //...
        PublicIncludePaths.AddRange(
        new string[] {
            "ProjectName",
            "ProjectName/Test"
        }
        //...
    );
    }
}

Add PublicIncludePaths to your *.Build.cs

public class ProjectName: ModuleRules
{
    public ProjectName(ReadOnlyTargetRules Target) : base(Target)
    {
        //...
        PublicIncludePaths.AddRange(
        new string[] {
            "ProjectName",
            "ProjectName/Test"
        }
        //...
    );
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文