[UE4]error LNK2005 on linking libprotobuf

Viewed 301

Having a small issue with conflicting libraries while packaging an Unreal Engine 4.27 project.

My project contains this gRPC library from google and I followed these steps to build it with CMake and after include it in my Unreal Project.

In addition my project requires enabling PixelStreaming plugin. However it seems that this plugin imported another version of protobuf which, on packaging is conflicting with the one included in gRPC.

The error is the following:

libprotobuf.lib(coded_stream.obj) : error LNK2005: "public: __cdecl google::protobuf::io::CodedOutputStream::CodedOutputStream(class google::protobuf::io::ZeroCopyOutputStream *,bool)" (??0CodedOutputStream@io@protobuf@google@@QEAA@PEAVZeroCopyOutputStream@123@_N@Z) already defined in webrtc.lib(coded_stream.obj)

appearing for different objs.

I came across similar issues as such but disabling gRPC is not a feasible solution for me.

  • Could anyone advise on how to "instruct" the built gRPC to use the existing protobuf library from Pixel Streaming plugin?
  • Which steps do I need to take to properly configure these conflicting libraries?
2 Answers

having the same issue with GCP libs. This issue seems to be caused by an bad commit of Protobuf (3.16.0 the branch linked by GRPC doesn't build correctly it seems)

If you build a different branch of protobuf manualy and use -DgRPC_PROTOBUF_PROVIDER=package option when building gRPC you should be able to get this to work. Im working in an msys environment so not 1 to 1 but my commands for building both protobuf and grpc are.

//protobuff C:/msys64/mingw64/bin/cmake.exe -H. -Bbuild-output -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=C:/msys64/mingw64/bin/mingw32-make.exe -DCMAKE_C_COMPILER=C:/msys64/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/msys64/mingw64/bin/g++.exe -DCMAKE_INSTALL_MESSAGE=NEVER -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_ABSL_PROVIDER=package

//gprc C:/msys64/mingw64/bin/cmake.exe -H. -Bbuild-output -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=C:/msys64/mingw64/bin/mingw32-make.exe -DCMAKE_C_COMPILER=C:/msys64/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/msys64/mingw64/bin/g++.exe -DCMAKE_INSTALL_MESSAGE=NEVER -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_STANDARD=17 -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_ABSL_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_RE2_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package

Building protobuf 3.20.x seemed to work for me (though having issues with absl further down the line)

What solved my issue was migrating to UE5.

Using the same steps with aforementioned grpc project, in UE5 new project. Having a libprotobuf.lib in ThirdPary folder within UE5 project the packaging process worked with no LINK conflicts. Not sure why UE packaging did not complain this time but what works, works!

Related