x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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

Product Version: UE 4.11
Tags:
more ▼

asked Apr 29 '16 at 12:52 PM in C++ Programming

avatar image

笑傲江湖-DA
216 12 24 30

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered May 02 '16 at 11:45 AM

avatar image

笑傲江湖-DA
216 12 24 30

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question