Compile protobuf on linux for ue4

Hi,

Platform: Ubuntu 20.04
Compiler: clang++ 10.0.0

I want to use google protobuf in my project as a plugin, so i download it from github repo and compile it with these params [./configure --prefix=/home/luoyu/Documents/protobuf-3.16.0/install CC=clang CXX=clang++ CXXFLAGS="-O2 -g -DNDEBUG -fPIC" --enable-shared=no].

But when i build my ue project with the libprotobuf.a, it always say undefined symbol xxxxxx.

Does anyone know how to fix it?

Hi. Did you have any luck with this? I’m in exactly the same situation now and can’t figure it out.
I even tried to build protobuf using the clang bundled with Unreal but still get “undefined symbol” with the most basic stuff like google::protobuf::internal::ArenaStringPtr::Set or google::protobuf::MessageLite::SerializeToString .

I figured this out.

The problem is you need to compile with both the correct C++ toolchain and the correct C++ standard library.

You were on the right track to build with the bundled clang, but you also need to compile against the bundled LibCxx (libc++). By default the bundled clang will build against libstdc++ - and that is what is causing the linking problems (ie protobuf is compiled against a different standard library to the one UnrealBuildTool is compiling the rest of the project against - so there are symbol mismatches when linking.)

Here is the full cmake command line I have found to build protobuf for unreal:

https://raw.githubusercontent.com/FuryGamesPtyLtd/Tasmania/main/Source/GoogleProtocolBuffers/Build.sh

(I got the options from LinuxToolChain.cs in UnrealBuildTool.)

(You’ll need to adjust for your unreal source paths of course)

And there is a checkin of the binary result libprotobuf.a in our public Tasmania plugin:

I have tested this as linking against monolithic targets. More work needs to be done - but at least the linking problem is fixed.

2 Likes

:pray: