当前位置: 首页 > article >正文

UE5 不同的编译模式下,module的组织形式

由于最近在琢磨UE5.4这个引擎,在学习过程中,碰到了一些非常有意思的事情,我在尝试把之前写的一些底层库搬到UE里面,比如底层库,网络库等等,我通过建立module,将这些库用源代码的方式整合进了UE5,因为我一直认为整体编译可以更方便的更改编译条件,因此都是用源代码的方式,比如一个atom的库,编译的C#脚本如下:

// Copyright Epic Games, Inc. All Rights Reserved.

using System.IO;
using UnrealBuildTool;

public class atom : ModuleRules
{
	public atom(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
            }
			);
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				//"Core",
				// ... add other public dependencies that you statically link with here ...
			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				 //"CoreUObject",
				 //"Engine",
				// "Slate",
				// "SlateCore",
				// ... add private dependencies that you statically link with here ...	
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);
    }
}

非常的简单,甚至屏蔽了所有依赖。 然后在入口的module引用这个库。其编译脚本如下:

// Copyright Epic Games, Inc. All Rights Reserved.

using System.IO;
using UnrealBuildTool;

public class Portal : ModuleRules
{
	public Portal(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;


        PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
                "atom/code",
            }
            );
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				// ... add other public dependencies that you statically link with here ...
				"atom"
			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"Engine",
				"Slate",
				"SlateCore",
				// ... add private dependencies that you statically link with here ...	
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);

    }
}

然后在public dependcy里面将该库引入。这样,就可以编译了。

但是问题来了,这个方法只适合客户端模式,不适合编辑器模式!因为客户端可以用静态库,而编辑器模式需要的是动态库。编辑器模式下甚至打不开编辑器。告诉我atom的dll不存在。

这个非常的坑,我想了很多办法都没有办法兼容两种模式。

后来,迫不得已,我只能将这个atom库改成静态库,不参与编译。其新的编译脚本如下:

// Copyright Epic Games, Inc. All Rights Reserved.

using System.IO;
using UnrealBuildTool;

public class atom : ModuleRules
{
	public atom(ReadOnlyTargetRules Target) : base(Target)
	{
		//PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

        Type = ModuleType.External;

        PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
            }
			);
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				//"Core",
				// ... add other public dependencies that you statically link with here ...
			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				 //"CoreUObject",
				 //"Engine",
				// "Slate",
				// "SlateCore",
				// ... add private dependencies that you statically link with here ...	
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);

        PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "lib", "x64", "atom_Debug.lib"));
    }
}

主要是将module的类型改成External,不参与编译,同时准备好这个库的静态库。

然后入口module的编译脚本如下:

// Copyright Epic Games, Inc. All Rights Reserved.

using System.IO;
using UnrealBuildTool;

public class Portal : ModuleRules
{
	public Portal(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;


        PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
                "atom/code",
            }
            );
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				// ... add other public dependencies that you statically link with here ...
				"atom",


			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"Engine",
				"Slate",
				"SlateCore",
				// ... add private dependencies that you statically link with here ...	
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);

    }
}

这个地方引入了静态库,再编译,就可以再客户端模式和编辑器模式下一同生效。


http://www.kler.cn/a/373105.html

相关文章:

  • Redis有什么不一样?
  • vue添加省市区
  • 无人机协同控制技术详解!
  • 模拟 DDoS 攻击与防御实验
  • 【刷题11】CTFHub技能树sql注入系列
  • 嵌入式学习-网络-Day03
  • 上市公司企业数字金融认知数据集(2001-2023年)
  • 【Android】ViewPager的MVP架构搭建
  • 谷歌浏览器安装axure插件
  • 为什么音频采样率通常是44.1kHz?
  • css 对称按钮,中间斜平行间隔,两头半圆
  • 动手学深度学习64 注意力机制
  • 线性数据结构之数组
  • 基于 GADF+Swin-CNN-GAM 的高创新扰动信号识别模型!
  • 在深度学习研究方向有哪些创新点
  • AI驱动的图像文本提取【Llama 3.2-Vision】
  • CSS实现回到顶部且平滑过渡
  • Zoho x Zendure:借助Zoho One加速从0到1出海品牌搭建
  • 【速查笔记】单片机
  • 让卷积神经网络来辨识马和人
  • 【折腾一上午】Java POI 导出 Excel 自适应列宽行高
  • STM32FreeRTOS 使用QSPI驱动nandFlash
  • Sentinel底层如何计算京东双十一线上系统实时QPS
  • 【SAP FICO】八大业务_6货币资金管理
  • 挑战Java面试题复习第3天,无人扶我青云志
  • ELK Stack与Graylog:强大的日志分析和可视化工具