简体   繁体   English

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

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

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

GameName.Build.cs -> 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 -> 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);*/
}

I compiled LuaJit for 64x, I'm not including the 32x build, do I need to? 我为64x编译了LuaJit,但我不包括32x构建,我需要吗? I don't intend to release my game for 32 bit systems as there's no point lol (Other than IOS because I'm pretty sure you have to upload 32 bit and 64 bit versions of the app :3) 我不打算在32位系统上发布我的游戏,因为没有意义(大笑)(除了IOS,因为我很确定您必须上传该应用的32位和64位版本:3)

I only ever included Lua51.lib once? 我只包含Lua51.lib一次吗? Have I done something wrong? 我做错什么了吗?

I know this is a pretty old question, but since I haven't seen an appropriate answer anywhere else and spent far too long figuring this out, I figured I'd help out any poor soul that is running into the same issue. 我知道这是一个很老的问题,但是由于我在其他任何地方都没有找到合适的答案,并且花了太长时间才弄清楚这个问题,所以我认为我会帮助遇到这个问题的可怜人。

The basic, afaik unavoidable problem is that the msvcbuild version of LuaJIT has extra symbols in it for (apparently) no reason. afaik不可避免的基本问题是LuaJIT的msvcbuild版本出于(显然)没有理由而在其中包含了额外的符号。 Here are the steps I took to compile a working version: 这是我编译工作版本所采取的步骤:

  • Download the LuaJIT Windows source 下载LuaJIT Windows源
  • Open the Makefile and 打开Makefile并
    • Set the mode to dynamic 将模式设置为动态
    • OPTIONALLY enable the DLUAJIT_ENABLE_LUA52COMPAT flag 可选地启用DLUAJIT_ENABLE_LUA52COMPAT标志
  • Compile using mingw32-make (mingw-w64) 使用mingw32-make(mingw-w64)进行编译
  • Copy the lua51.dll file to another folder. 将lua51.dll文件复制到另一个文件夹。
  • Using the x64 Native Tools Comand Prompt for VS 2017, export the external symbols found in the DLL dumpbin /EXPORTS lua51.dll > lua51.exports 使用适用于VS 2017的x64 Native Tools Comand Prompt,导出在DLL dumpbin /EXPORTS lua51.dll > lua51.exports找到的外部符号
  • From the exports file, create a separate .def file pointing to the dll containing all the symbol references 从导出文件中,创建一个指向包含所有符号引用的dll的单独的.def文件
  • Using the x64 Native Tools Comand Prompt for VS 2017, generate the lib and exp files based on the def file lib /def:lua51.def /out:lua51.lib 使用适用于VS 2017的x64 Native Tools Comand Prompt,基于def文件lib /def:lua51.def /out:lua51.lib生成lib和exp文件

You now have a DLL and a LIB that links to it! 您现在有了一个DLL和一个链接到它的LIB!

  • You may now copy the dll, lib and exp file to the location you want to install Lua to. 您现在可以将dll,lib和exp文件复制到要将Lua安装到的位置。
  • Finish following the Installation instructions on the LuaJIT website, for my own paths, that was 按照我自己的路径,按照LuaJIT网站上的安装说明进行操作,即
    • Copy all files from K:/Git Repos/luajit205-52-libdll/luajit205-52-dll/src to C:/LUA 将所有文件从K:/ Git Repos / luajit205-52-libdll / luajit205-52-dll / src复制到C:/ LUA
    • Copy the files from K:/Git Repos/luajit205-52-libdll/luajit205-52-dll/src/jit to C:/LUA/lua/jit 将文件从K:/ Git Repos / luajit205-52-libdll / luajit205-52-dll / src / jit复制到C:/ LUA / lua / jit

I wrote out the full procedure and how I worked through it, along with the dll/lib/exp I use to one of my git repos, so for extra doc and potentially useful files, head here: 我写出了完整的过程以及如何使用它,以及我在其中一个git仓库中使用的dll / lib / exp,所以对于其他文档和可能有用的文件,请转到此处:
https://github.com/Zaltu/luajit205-52-libdll https://github.com/Zaltu/luajit205-52-libdll

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

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