假设要添加名为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