Download

build failed with 3rd lib Protobuf: error LNK2019: unresolved external symbol

my steps for protobuf using is following:
1, first I add includes and libraries in MyProject.Build.cs:


// Fill out your copyright notice in the Description page of Project Settings.
using System.IO;
using UnrealBuildTool;

public class MyProject : ModuleRules
{
    RulesAssembly r;

    private string ModulePath
    {
        get { return Path.GetDirectoryName( r.GetModuleFileName(this.GetType().Name).CanonicalName); }
    }

    private string ThirdPartyPath
    {
        get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
    }

	//this's path which contains all header and cpp files generated by protoc
    private string ProtocGeneratePath
    {
        get { return Path.GetFullPath(Path.Combine(ModulePath, "../../../../common/build/src/")); }
    }

    public MyProject(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore" });

		PrivateDependencyModuleNames.AddRange(new string] { "UMG", "Slate", "SlateCore" });

        PrivateDependencyModuleNames.AddRange(new string] { "Sockets", "Networking" });

        FileReference CheckProjectFile;
        UProjectInfo.TryGetProjectForTarget("HuaiKX", out CheckProjectFile);
        r = RulesCompiler.CreateProjectRulesAssembly(CheckProjectFile);

        AddProtocGenPath(Target);

        LoadProtobuf(Target);
    }

    public bool AddProtocGenPath(TargetInfo Target)
    {
        PublicIncludePaths.Add(ProtocGeneratePath);
        System.Console.WriteLine("#### Set ProtocGen includes path ####:" + ProtocGeneratePath);
        return true;
    }

    //add protobuf lib
    public bool LoadProtobuf(TargetInfo Target)
    {
        //Library path
        string PlatformString = "";
        switch(Target.Platform)
        {
            case UnrealTargetPlatform.Win64:
                {
                    PlatformString = ".x64.lib";
                    break;
                }
            case UnrealTargetPlatform.Win32:
                {
                    PlatformString = ".x86.lib";
                    break;
                }
            case UnrealTargetPlatform.Android:
                {
                    PlatformString = ".ndk.a";
                    break;
                }
        }
        string LibrariesPath = Path.Combine(ThirdPartyPath, "Protobuf", "Libraries", "libprotobuf-lite" + PlatformString);
        PublicAdditionalLibraries.Add(LibrariesPath);

        //Include path
        string IncludePath = Path.Combine(ThirdPartyPath, "Protobuf", "Includes");
        PublicIncludePaths.Add(IncludePath);

        System.Console.WriteLine("#### Set Protobuf Libraries ####:" + LibrariesPath);
        System.Console.WriteLine("#### Set Protobuf Includes ####:" + IncludePath);
      
        return true;
    }
}


2, then I build libprotobuf-lite library from source of Protobuf 2.6, and copy includes into my project.

3,then I code a function to handle protobuf msg:


bool HMsgSendFunc::SendCustomMsg(int msgid, ::google::protobuf::MessageLite& msglite)
{
	...
	//logic code here
	...
	
	return true;
}

so far building project works right and has no error

but when I add a protobuf msg in my code:


move_to instance;

a compile-time error occurred while compiling:
error LNK2019: unresolved external symbol "public: __cdecl move_to::move_to(void)"

the template of msg **move_to **is below:


option optimize_for = LITE_RUNTIME;

message move_to {
	required int32  x	= 1;
	required int32 	y	= 2;
}

I generate cpp files by using command:


protoc.exe --proto_path=custom_msg --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:build/src custom_msg/battle.proto custom_msg/test.proto

how to resolve this problem? hope help

I worked it out:building a single static lib for c++ code generated by protoc, then link into UE4 project and include headers, so, it works fine.

大神,虚幻里打包安卓,protobuf库编译失败,该如何弄