虚幻引擎4链接静态第三方库/ SDK(libZPlay)

时间:2015-06-25 00:40:58

标签: c++ visual-studio-2013 static-linking unresolved-external unreal-engine4

我正在尝试将静态第三方库链接到虚幻引擎4。

我正在尝试添加名为libZPlay的第三方库/ SDK。我尝试了Linking Static Libraries Using The Build System wiki指南,但是遇到了问题。我使用的是UE 4.8.0,而libZPlay是一个32位的库。

以下是遵循指南后我当前的构建文件:

using UnrealBuildTool;
using System.IO;

public class Rhythm : ModuleRules{
//for linking 3rd party libraries 
private string ModulePath{
    get { return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name)); }
}
private string ThirdPartyPath{
    get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
}
//normal after this
public Rhythm(TargetInfo Target){
    MinFilesUsingPrecompiledHeaderOverride = 1;//faster builds
    bFasterWithoutUnity = true;//faster builds
    PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
    PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });//for UMG

    LoadlibZPlay(Target); //load libZPlay library
}

public bool LoadlibZPlay(TargetInfo Target){
    bool isLibrarySupported = false;

    if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32)){
        isLibrarySupported = true;

        string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86"; //prob not needed since only one version of the file
        string LibrariesPath = Path.Combine(ThirdPartyPath, "libZPlay", "Libraries");

        PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "libzplay.lib"));
        //PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "libzplay_borland.lib"));
        PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "libzplay.a"));
        //PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "libzplay.dll"));
        PublicDelayLoadDLLs.Add(Path.Combine(LibrariesPath, "libzplay.dll"));
    }

    if (isLibrarySupported){
        //include path
        PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "libZPlay", "Includes"));
    }

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

    return isLibrarySupported;
}

}

我在项目的根目录中有一个ThirdParty文件夹,其中包含一个包含带有头文件的Includes文件夹的libZPlay文件夹。此外,在libZPlay文件夹中有一个Libraries文件夹,其中包含我的libZPlay.dll,libZPlay.lib和libZPlay.a文件。头文件包含在以下方式中:#include" ../../ ThirdParty / libZPlay / Includes / libzplay.h"。添加完所有内容后,还会重新生成visual studio文件。

我尝试从所谓的外部库运行一个名为' CreateZPlay()'如下图所示:

void UMusicAnalyzerWidget::initilizeMusicAnalyzer(){
  player = libZPlay::CreateZPlay();
  filePath = "D:/Christian/Music/Archive/Stick Me In My Heart (Radio Edit).mp3";
}

'播放'是在UMusicAnalyzerWidget类中创建的ZPlay指针,该函数几乎创建并初始化对象。但是,在尝试构建/编译时,我会收到以下错误:

Error   8   error LNK2019: unresolved external symbol __imp_CreateZPlay referenced in function "public: void __cdecl UMusicAnalyzerWidget::execinitilizeMusicAnalyzer(struct FFrame &,void * const)" (?execinitilizeMusicAnalyzer@UMusicAnalyzerWidget@@QEAAXAEAUFFrame@@QEAX@Z)    D:\GitHub\Rhythm\Rhythm\Intermediate\ProjectFiles\MusicAnalyzerWidget.cpp.obj   Rhythm
Error   9   error LNK1120: 1 unresolved externals   D:\GitHub\Rhythm\Rhythm\Binaries\Win64\UE4Editor-Rhythm.dll 1   1   Rhythm
Error   10  error : Failed to produce item: D:\GitHub\Rhythm\Rhythm\Binaries\Win64\UE4Editor-Rhythm.dll D:\GitHub\Rhythm\Rhythm\Intermediate\ProjectFiles\ERROR Rhythm
Error   11  error MSB3075: The command ""D:\Programs\Epic Games\4.8\Engine\Build\BatchFiles\Rebuild.bat" RhythmEditor Win64 Development "D:\GitHub\Rhythm\Rhythm\Rhythm.uproject" -rocket" exited with code 5. Please verify that you have sufficient rights to run this command.   C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets   43  5   Rhythm

在一堆环顾四周后,我陷入困境,不知道如何继续。我相信它可能是因为这是一个32位的库(没有任何64位版本),而虚幻引擎4只能编译64位。任何见解都会很棒!

1 个答案:

答案 0 :(得分:0)

您提供的链接实际上证实了您怀疑UE4不支持32位库:

使用标准的静态库项目,我们将针对x86(32位)计算机,这些计算机不适用于UE4工具集。

您需要64位版本。