1. 程式人生 > 其它 >UE4匯入第三方庫筆記_4.25/4.26

UE4匯入第三方庫筆記_4.25/4.26

摘抄自該文章

對於所有第三方庫都應該先加入對標頭檔案目錄的包含:

在模組的Build.cs檔案中,加入對應的第三方庫的標頭檔案包含路徑:

  • PublicIncludePaths.Add(path);//包含目錄中的標頭檔案並公開到外部模組
  • PrivateIncludePaths.Add(Path);//包含目錄中的標頭檔案並不公開到外部模組
對於外掛中的模組:

PublicIncludePaths和PrivateIncludePaths可以接受特殊字串開頭的字串:

  • $(ModuleDir) 表示模組目錄(D:\UE4_Project\testSlate\Plugins\MotionMocap\Source\MotionMocap)
  • $(PluginDir) 表示外掛目錄(D:\UE4_Project\testSlate\Plugins\MotionMocap)
  • $(EngineDir) 表示引擎目錄(D:\Program Files (x86)\UE4\UE_4.22\Engine)
  • $(ProjectDir) 表示工程目錄(D:\UE4_Project\testSlate)
對於非外掛中的模組:
  • PublicIncludePathsPrivateIncludePaths不接受特殊字串。
  • 如果path是相對路徑,則是從工程目錄的 Source開始D:\UE4_Project\testSlate\Source\ 開始的相對路徑。

引入lib與dll(示例):

檔案路徑
lib:

  • 包含庫的搜尋路徑
  • 包含要使用的庫
  • 特殊的,對於 .so.a檔案可以不加字尾名
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "Libs","sqlite3.lib");
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Includes"));

dll:

  • 包含庫同上
  • dll檔案需要複製到專案路徑的Binary下,如果沒有,模組會載入失敗,使用RuntimeDependencies.Add(TargetPath,path)
    執行後會自動複製並新增依賴
 String DllPath = Path.Combine(ModuleDirectory, "Binaries", "sqlite3.dll");
 RuntimeDependencies.Add(Path.Combine("$(ProjectDir)/Binaries/Win64/sqlite3.dll"), DllPath);
 //延遲載入
 PublicDelayLoadDLLs.Add("sqlite3.dll");

RuntimeDependencies,並不僅限於dll,也可以用於其他檔案的操作,但path路徑必須是以工程路徑開始的,比如工程路徑為D:\UE4_Project\testSlate\,則path必須是D:\UE4_Project\testSlate\包含的目錄下的檔案。
path和sourcepath可接受以下特殊字串:

$(ModuleDir)
表示模組目錄(D:\UE4_Project\testSlate\Plugins\MotionMocap\Source\MotionMocap)
$(PluginDir)
表示外掛目錄,僅在外掛模組中有效,遊戲模組會報錯(D:\UE4_Project\testSlate\Plugins\MotionMocap)
$(EngineDir)
表示引擎目錄(D:\Program Files (x86)\UE4\UE_4.22\Engine)
$(ProjectDir)
表示工程目錄(D:\UE4_Project\testSlate)
$(TargetOutputDir)
表示Directory containing the output executable,也就是exe檔案輸出目錄,這個好像只在打包時有效。
$(BinaryOutputDir)
表示Directory containing the binary that links thismodule.也就是dll檔案目錄

Android
檔案路徑

  • 需要匯入xml檔案和Launch模組,然後再xml檔案中複製和引入包
  • [詳情參考](https://zhuanlan.zhihu.com/p/34374244
if(Target.Platform == UnrealTargetPlatform.Android)
{
    PrivateDependencyModuleNames.AddRange(new string[] { "Launch" });
    string PluginPath = Utils.MakePathRelativeTo(ModuleDirectory, Target.RelativeEnginePath);
    AdditionalPropertiesForReceipt.Add("AndroidPlugin", Path.Combine(PluginPath, "Compress_UPL.xml"));
}

IOS
檔案路徑

  • 如圖
else if (Target.Platform == UnrealTargetPlatform.IOS)
 {
     PublicAdditionalFrameworks.Add(
            new Framework(
                "Crasheye",        //name
                "IOS/Crasheye.embeddedframework.zip"       // path
            )
     );
}