【UE基础】UE4导入第三方库_4.25/4.26

  • Post author:
  • Post category:其他


对于所有第三方库都应该先加入对头文件目录的包含:


在模块的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)


对于非插件中的模块:


  • PublicIncludePaths



    PrivateIncludePaths

    不接受特殊字符串。

  • 如果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
            )
     );
}