UE4链接第三方库

首先写一个第三方库

.h

[cpp]  view plain  copy
  1. #pragma once  
  2. #ifndef __MYTEST_LIB_H__  
  3. #define __MYTEST_LIB_H__  
  4. #include <string>  
  5. #include <iostream>  
  6.   
  7. int Addd(int a, int b);  
  8.   
  9. #endif  
.cpp

[cpp]  view plain  copy
  1. #include "stdafx.h"  
  2. #include "MyDll.h"  
  3. int Addd(int a, int b)   
  4. return a + b; }  
生成静态库lib

第一种,项目调用:

和Source同级目录下建个ThirdParty文件夹,在ThirdParty下再新建Includes和Libs文件夹,把上面的.h丢进Includes,lib丢进Libs

然后在项目Build.cs下添加:

[cpp]  view plain  copy
  1. using System.IO;  
  2.  private string ModulePath  
  3.     {  
  4.         get{ return ModuleDirectory; }//return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name));   
  5.     }  
  6.     private string ThirdPartyPath  
  7.     {  
  8.         get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }  
  9.     }  
在 public TTTTT(TargetInfo Target)下加上:同下LoadThirdPartyLib(Target);函数

[cpp]  view plain  copy
  1. // PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "Includes"));  
  2. /  PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Libs""XXX.lib"));  
接下来就可以在.h文件里#include你的第三方头文件了

第二种,插件调用:

同样在插件Source同级下新建ThirdParty文件夹,在ThirdParty下多一层MyTestLib文件夹,再往下新建Includes和Libs文件夹,把上面的.h丢进Includes,lib丢进Libs

扫描二维码关注公众号,回复: 1508690 查看本文章

然后在插件Build.cs下添加:

[cpp]  view plain  copy
  1. using System.IO;  
  2. private string ModulePath //第三方库  
  3.     {  
  4.         // get { return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name)); }  
  5.         get { return ModuleDirectory; }  
  6.     }  
  7.   
  8.     private string ThirdPartyPath//第三方库  
  9.     {  
  10.         get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }  
  11.     }  
  12.     private string MyLibPath //第三方库MyTestLib的目录  
  13.     {  
  14.         get { return Path.GetFullPath(Path.Combine(ThirdPartyPath, "MyTestLib")); }  
  15.     }  
 public Test(TargetInfo Target)下添加一个 LoadThirdPartyLib(Target);函数,下面是函数实现

[cpp]  view plain  copy
  1. public bool LoadThirdPartyLib(TargetInfo Target)  
  2.    {  
  3.        bool isLibrarySupported = false;  
  4.        if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))//平台判断  
  5.        {  
  6.            isLibrarySupported = true;  
  7.            System.Console.WriteLine("----- isLibrarySupported true");  
  8.            string LibrariesPath = Path.Combine(MyLibPath, "Libs");  
  9.            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "MyThirdParty.lib"));//加载第三方静态库.lib  
  10.        }  
  11.   
  12.        if (isLibrarySupported) //成功加载库的情况下,包含第三方库的头文件  
  13.        {  
  14.            // Include path  
  15.            System.Console.WriteLine("----- PublicIncludePaths.Add true");  
  16.            PublicIncludePaths.Add(Path.Combine(MyLibPath, "Includes"));  
  17.        }  
  18.        return isLibrarySupported;  
  19.    }  
接下来就可以在.h文件里#include你的第三方头文件了

下面是分享的代码http://download.csdn.net/detail/u014532636/9853272

参考:

https://blog.csdn.net/lunweiwangxi3/article/details/50468593

http://blog.csdn.net/Szu_IT_Man/article/details/58232638

http://blog.csdn.net/yangxuan0261/article/details/52098104

http://blog.csdn.net/lunweiwangxi3/article/details/48373033


加载DLL参考:

http://blog.csdn.net/baidu_27276201/article/details/75675836?locationNum=2&fps=1

https://wiki.unrealengine.com/Linking_Dlls

http://blog.csdn.net/szu_it_man/article/details/58232638#引用dll

猜你喜欢

转载自blog.csdn.net/biewangliaowo/article/details/80334789