简述

  • 本例以插件形式测试
  • 使用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

【UE4 C++】调用外部链接库 lib静态库的更多相关文章

  1. 自己在linux上编译、链接、动态库和静态库的学习笔记

    在平常的项目中,我们都是使用公司要求的makefile.makedebug一类的文件,因此,在编译.链接.生成和链接动态库与静态库的时候,我们只是简单的使用一些已经设置的变量,只是简单的修改.添加一些 ...

  2. Linux链接库一(动态库,静态库,库放在什么路径下)

    http://www.cppblog.com/wolf/articles/74928.html http://www.cppblog.com/wolf/articles/77828.html http ...

  3. CMake 添加头文件目录,链接动态、静态库(添加子文件夹)

    CMake支持大写.小写.混合大小写的命令. 当编译一个需要第三方库的项目时,需要知道: 去哪找头文件(.h),-I(GCC) INCLUDE_DIRECTORIES() 去哪找库文件(.so/.dl ...

  4. malloc,colloc,realloc内存分配,动态库,静态库的生成与调用

     1.在main方法里面直接定义一个很大的数组的时候.可能会出现栈溢出:错误代码演示: #include<stdio.h> #include<stdlib.h> void ...

  5. Linux系统中“动态库”和“静态库”那点事儿 /etc/ld.so.conf 动态库的后缀为*.so 静态库的后缀为 libxxx.a ldconfig 目录名

    Linux系统中“动态库”和“静态库”那点事儿 /etc/ld.so.conf  动态库的后缀为*.so  静态库的后缀为 libxxx.a   ldconfig   目录名 转载自:http://b ...

  6. Linux系统中“动态库”和“静态库”那点事儿【转】

    转自:http://blog.chinaunix.net/uid-23069658-id-3142046.html 今天我们主要来说说Linux系统下基于动态库(.so)和静态(.a)的程序那些猫腻. ...

  7. Linux系统中“动态库”和“静态库”那点事儿

    摘自http://blog.chinaunix.net/uid-23069658-id-3142046.html 今天我们主要来说说Linux系统下基于动态库(.so)和静态(.a)的程序那些猫腻.在 ...

  8. linux动态库与静态库混合连接

      1, 在应用程序需要连接外部库的情况下,linux默认对库的连接是使用动态库,在找不到动态库的情况下再选择静态库.使用方式为: gcc test.cpp -L. -ltestlib 如果当前目录有 ...

  9. Windows 下VC++6.0制作、使用动态库和静态库

    Windows 下VC++6.0制作.使用动态库和静态库 一.VC++6.0制作.使用静态库 静态库制作 1.如图一在VC++6.0中new一个的为win32 static library工程并新建一 ...

随机推荐

  1. noip模拟32

    \(\color{white}{\mathbb{山高而青云冷,池深而蛟穴昏,行以慎步,援以轻身,名之以:落石}}\) 开题发现 \(t1\) 80分特别好写,于是先写了 但是这个做法没有任何扩展性,导 ...

  2. 模拟9:T1:斐波那契

    Description: 题目描述:   小 C 养了一些很可爱的兔子.   有一天,小 C 突然发现兔子们都是严格按照伟大的数学家斐波那契提出的模型来进行繁衍:一对兔子从出生后第二个月起,每个月刚开 ...

  3. ubuntu14.04 安装MySQL 5.7

    ubuntu14.04 默认在线安装MySQL 5.5 1) wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb 2) dpk ...

  4. 乐肴2.0环境改名后,需要删除原来的软链接(public/storage)

    rm -rf public/storage php artisan storage:link

  5. vue+element+echarts柱状图+列表

    前端由vue+element搭建框架,引入vue和element的index.js和css就可以写页面: 页面和js可以echarts官网实例看下都是有的,主要看下如何动态赋值: 柱状图和列表: &l ...

  6. 常见shell脚本测试题 if/case语句

    1.检查用户家目录中的 test.sh 文件是否存在,并且检查是否有执行权限2.提示用户输入100米赛跑的秒数,要求判断秒数大于0且小于等于10秒的进入选拔赛,大于10秒的都淘汰,如果输入其它字符则提 ...

  7. Markdown主要语法及使用

    最近,我发现使用Markdown这一标记语言的人越来越多了,我也去试了一下,感觉确实在编辑文档上方便了很多.于是我将一些关于Markdown的语法和编写时的快捷键整理在这里,方便以后查阅,也欢迎评论区 ...

  8. mysql触发器实时检测一条语句进行备份删除

    问题描述:用户有一个这样一个需求,在一张表里会不时出现 "违规" 字样的字段,需要在出现这个字段的时候,把整行的数据删掉.这是个采集任务,如果发现有"违规"字样 ...

  9. EditPlus配置C/C++运行环境

    1.安装MinGW和EditPlus 2.打开EditPlus ctrl+1 编译 ctrl+2 运行

  10. windows 下使用 mingw编译器 调试时 无法跟进源码

    windows 下使用 mingw编译器 调试时 无法跟进源码 最近在公司使用QT 开发,官方在线下载的 安装的QT mingw 都是没有debug版本的 由于没有debug版本动态库 所以你调试的时 ...