简述

  • 本例以插件形式测试
  • 使用Lib引用,打包程序运行不用再拷贝lib文件
  • 需要 lib 文件和 .h 头文件

lib部分的代码

  • .h 头文件
    #pragma once
    #ifndef __MYTEST_LIB_H__
    #define __MYTEST_LIB_H__
    #include <string>
    #include <iostream> int myPrint( int _age); #endif
  • .cpp 文件
    #include "MyTestLib.h"
    
    int myPrint(int _age)
    {
    return _age + 1000;
    }

UE4 插件代码

Plugin lib文件部署

插件 build.cs设置

using System.IO;
namespace UnrealBuildTool.Rules
{
public class JsonPlugin : ModuleRules
{
private string ModulePath
{
// get { return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name)); }
get { return ModuleDirectory; }
} private string ThirdPartyPath
{
get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
}
private string MyLibPath //第三方库MyTestLib的目录
{
get { return Path.GetFullPath(Path.Combine(ThirdPartyPath, "mylib")); }
} public JsonPlugin(TargetInfo Target)
{
PublicIncludePaths.AddRange(
new string[] {
"JsonPlugin/Public",
// ... add public include paths required here ...
}
); PrivateIncludePaths.AddRange(
new string[] {
"JsonPlugin/Private",
// ... add other private include paths required here ...
}
); PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"CoreUObject",
"Engine",
"HTTP",
"Json"
// ... add other public dependencies that you statically link with here ...
}
); PrivateDependencyModuleNames.AddRange(
new string[]
{
// ... add private dependencies that you statically link with here ...
}
); DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
); LoadThirdPartyLib(Target);
} public bool LoadThirdPartyLib(TargetInfo Target)
{
bool isLibrarySupported = false;
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))//平台判断
{
isLibrarySupported = true;
System.Console.WriteLine("----- isLibrarySupported true");
//string PlatformSubPath = (Target.Platform == UnrealTargetPlatform.Win64) ? "Win64" : "Win32";
string LibrariesPath = Path.Combine(MyLibPath, "Lib");
PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath,/* PlatformSubPath,*/ "MyTestLib.lib"));//加载第三方静态库.lib
} if (isLibrarySupported) //成功加载库的情况下,包含第三方库的头文件
{
// Include path
System.Console.WriteLine("----- PublicIncludePaths.Add true");
PublicIncludePaths.Add(Path.Combine(MyLibPath, "Include"));
}
return isLibrarySupported;
}
}
}

调用

  • JsonFunction.cpp代码
#include "../ThirdParty/mylib/Include/MyTestLib.h"

int UJsonFunction::MyOutput()
{
int str = myPrint(100); //lib 里的函数
return str;
}

原文最早发布于:https://blog.csdn.net/Szu_IT_Man/article/details/58232638

最新文章

  1. c++ 陷阱
  2. html5 炫酷的字幕雨
  3. 从阿里巴巴IPO联想到创始人和资方关系
  4. 远程重装centos6
  5. mysql导入sql文件,乱码,一个例子
  6. 在后台 .cs 中执行前台的js 函数
  7. Asp.net上传文件Request.files获取不到文件
  8. 利用 js 实现弹出蒙板(model)功能
  9. Windows 7 常用快捷键 命令
  10. hdu 2034
  11. spring、spring mvc、mybatis框架整合基本知识
  12. Java中equals和==之间的区别
  13. 数论:px+py 不能表示的最大数为pq-p-q的证明
  14. PDF文件怎么转换成PPT
  15. yum解决 &quot;Couldn&#39;t resolve host &#39;apt.sw.be&#39;&quot; 错误
  16. IP通信基础学习第四周(下)
  17. hexo博客pure主题解决不蒜子计数不显示的问题
  18. EntityFramework使用总结(与MVC4.0实现CURD操作)
  19. 【WPF】右键菜单ContextMenu可点击区域太小的问题
  20. linux下maven项目clean失败

热门文章

  1. Vue项目-初始化之 vue-cli
  2. js不同地图坐标系经纬度转换(天地图,高德地图,百度地图,腾讯地图)
  3. 解决使用tomcat服务器发布web项目时出现URL中文乱码的问题
  4. 彻底搞明白PHP的中引用的概念
  5. PHP中类的自动加载
  6. TP5数据库数据变动日志记录设计
  7. 环形链表II
  8. 队列,一种&quot;公平&quot;的数据结构
  9. gin 源码阅读(2) - http请求是如何流入gin的?
  10. Typescript, ES6