UE4添加第三方库

假设要添加名为xxx的库,我们需要dll,lib以及头文件,切记要带上lib,因为它保存了dll里的函数地址。如果没有lib,我们就需要在运行时根据函数名获取函数地址,使用很不便。

添加模块xxxLibrary:

public class xxxLibrary : ModuleRules
{
	public xxxLibrary(ReadOnlyTargetRules Target) : base(Target)
	{
		Type = ModuleType.External;

		if (Target.Platform == UnrealTargetPlatform.Win64)
		{
			// Add the import library
			PublicLibraryPaths.Add(Path.Combine(ModuleDirectory, "lib"));
            PublicAdditionalLibraries.Add("xxx.lib");
            PublicDelayLoadDLLs.Add("xxx.dll");
            RuntimeDependencies.Add(Path.Combine(ModuleDirectory, "bin", "xxx.dll"), StagedFileType.NonUFS);
            RuntimeDependencies.Add(Path.Combine(ModuleDirectory, "bin", "xxx.pdb"), StagedFileType.DebugNonUFS);
            PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "include"));
		}
	}
}

 其他模块如果要调用xxx,需要加载xxx.dll。常见的做法是调用方模块启动时通过FPlatformProcess::GetDllHandle(*LibraryPath) 加载xxx.dll,模块关闭时通过FPlatformProcess::FreeDllHandle(LibraryHandle) 卸载xxx.dll

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值