繁体   English   中英

在UE4中集成LuaJit时发生LNK2005错误(虚幻引擎4)

[英]LNK2005 error when integrating LuaJit in UE4 (Unreal Engine 4)

lua51.lib(lua51.dll):错误LNK2005:_vsnprintf已在libcurl_a.lib(cryptlib.obj)中定义

GameName.Build.cs->

// Fill out your copyright notice in the Description page of Project Settings.

using System.IO;
using UnrealBuildTool;

public class GameName : ModuleRules
{
    private string ThirdPartyPath
    {
        get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../ThirdParty/")); }
    }  
    private bool LoadLua()
    {
        bool isLibSupported = false;

        string LibrariesPath = Path.Combine(ThirdPartyPath, "Lua", "libraries");

        PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "lua51.lib"));

        PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "Lua", "includes"));

        Definitions.Add(string.Format("WITH_LUA_BINDING={0}", isLibSupported ? 1 : 0));

        return true;
    }
    public GameName(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

        PrivateDependencyModuleNames.AddRange(new string[] {  });

        LoadLua();

        // Uncomment if you are using Slate UI
        // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

        // Uncomment if you are using online features
        // PrivateDependencyModuleNames.Add("OnlineSubsystem");

        // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
    }
}

ActorName.cpp->

// Fill out your copyright notice in the Description page of Project Settings.

#include "ActorName.h"

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "luaconf.h"
#pragma comment(lib, "lua51.lib")
}

// Sets default values
APart::APart()
{
    // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;
}

// Called when the game starts or when spawned
void APart::BeginPlay()
{
    Super::BeginPlay();
    lua_State *L = luaL_newstate();
    luaL_openlibs(L);
    FVector NewLocation = GetActorLocation();
    NewLocation.Z = NewLocation.Z + 200.0f;
}

// Called every frame
void APart::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    /*FVector NewLocation = GetActorLocation();
    float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
    NewLocation.Z += DeltaHeight * 100.0f;
    NewLocation.Y += DeltaHeight * 800.0f;//Scale our height by a factor of 20
    RunningTime += DeltaTime;
    SetActorLocation(NewLocation);*/
}

我为64x编译了LuaJit,但我不包括32x构建,我需要吗? 我不打算在32位系统上发布我的游戏,因为没有意义(大笑)(除了IOS,因为我很确定您必须上传该应用的32位和64位版本:3)

我只包含Lua51.lib一次吗? 我做错什么了吗?

我知道这是一个很老的问题,但是由于我在其他任何地方都没有找到合适的答案,并且花了太长时间才弄清楚这个问题,所以我认为我会帮助遇到这个问题的可怜人。

afaik不可避免的基本问题是LuaJIT的msvcbuild版本出于(显然)没有理由而在其中包含了额外的符号。 这是我编译工作版本所采取的步骤:

  • 下载LuaJIT Windows源
  • 打开Makefile并
    • 将模式设置为动态
    • 可选地启用DLUAJIT_ENABLE_LUA52COMPAT标志
  • 使用mingw32-make(mingw-w64)进行编译
  • 将lua51.dll文件复制到另一个文件夹。
  • 使用适用于VS 2017的x64 Native Tools Comand Prompt,导出在DLL dumpbin /EXPORTS lua51.dll > lua51.exports找到的外部符号
  • 从导出文件中,创建一个指向包含所有符号引用的dll的单独的.def文件
  • 使用适用于VS 2017的x64 Native Tools Comand Prompt,基于def文件lib /def:lua51.def /out:lua51.lib生成lib和exp文件

您现在有了一个DLL和一个链接到它的LIB!

  • 您现在可以将dll,lib和exp文件复制到要将Lua安装到的位置。
  • 按照我自己的路径,按照LuaJIT网站上的安装说明进行操作,即
    • 将所有文件从K:/ Git Repos / luajit205-52-libdll / luajit205-52-dll / src复制到C:/ LUA
    • 将文件从K:/ Git Repos / luajit205-52-libdll / luajit205-52-dll / src / jit复制到C:/ LUA / lua / jit

我写出了完整的过程以及如何使用它,以及我在其中一个git仓库中使用的dll / lib / exp,所以对于其他文档和可能有用的文件,请转到此处:
https://github.com/Zaltu/luajit205-52-libdll

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM