[UE4]error LNK2005 on linking libprotobuf

Hello,

We have been struggling with a problem while packaging my app due to duplicate/conflicting lib existence in the build in UE 4.27. The duplicate library is “libprotobuf”

The 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.

—What I already tried was deleting the duplicate library from my project that was used by grpc and modify the “include” of the protobuf files to be the one from webRTC, however this resulted in methods conflicting as the versions of protobuf are different.

—Following the advice in this post CMake is called pointing to the path where Unreal’s OpenSSL is located by using these commands:

SET UE_THIRD_PARTY_DIR=C:\Program Files\Epic Games\UE_4.27\Engine\Source\ThirdParty

cmake .. -G "Visual Studio 17 2022" ^
    -DCMAKE_CXX_STANDARD_LIBRARIES="Crypt32.Lib User32.lib Advapi32.lib" ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DCMAKE_CONFIGURATION_TYPES=Release ^
    -Dprotobuf_BUILD_TESTS=OFF ^
    -DgRPC_ZLIB_PROVIDER=package ^
    -DZLIB_INCLUDE_DIR="%UE_THIRD_PARTY_DIR%\zlib\v1.2.8\include\Win64\VS2015" ^
    -DZLIB_LIBRARY_DEBUG="%UE_THIRD_PARTY_DIR%\zlib\v1.2.8\lib\Win64\VS2015\Debug\zlibstatic.lib" ^
    -DZLIB_LIBRARY_RELEASE="%UE_THIRD_PARTY_DIR%\zlib\v1.2.8\lib\Win64\VS2015\Release\zlibstatic.lib" ^
    -DgRPC_SSL_PROVIDER=package ^
    -DLIB_EAY_LIBRARY_DEBUG="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\Lib\Win64\VS2015\Debug\libcrypto.lib" ^
    -DLIB_EAY_LIBRARY_RELEASE="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\Lib\Win64\VS2015\Release\libcrypto.lib" ^
    -DLIB_EAY_DEBUG="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\Lib\Win64\VS2015\Debug\libcrypto.lib" ^
    -DLIB_EAY_RELEASE="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\Lib\Win64\VS2015\Release\libcrypto.lib" ^
    -DOPENSSL_INCLUDE_DIR="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\include\Win64\VS2015" ^
    -DSSL_EAY_DEBUG="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\Lib\Win64\VS2015\Debug\libssl.lib" ^
    -DSSL_EAY_LIBRARY_DEBUG="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\Lib\Win64\VS2015\Debug\libssl.lib" ^
    -DSSL_EAY_LIBRARY_RELEASE="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\Lib\Win64\VS2015\Release\libssl.lib" ^
    -DSSL_EAY_RELEASE="%UE_THIRD_PARTY_DIR%\OpenSSL\1.1.1\Lib\Win64\VS2015\Release\libssl.lib"

However, we also need to make sure that cmake building grpc is also using the existing libprotobuf.lib and not the one included within the cloned grpc project.
The issue here is, that the conflict while packaging mentions libprotobuf.lib methods being already defined in webrtc.lib.

—In addition to this, we tried specifying the path of the existing libprotobuf, however, when adding the flag:

-DProtobuf_DIR="%UE_THIRD_PARTY_DIR%\WebRTC\4147\Lib\Win32\Release\webrtc.lib" ^ in the above command the build ignores it with the message:

CMake Warning:
Manually-specified variables were not used by the project:

Protobuf_DIR
  • How could we instruct our grpc project to build the grpc files using the libprotobuf from webrtc, as libprotobuf.lib is included within webrtc.lib and not accessible individually.
  • If we manage to build the files using the existing libprotobuf from webrtc, do we still need the ThirdParty folders mentioned in the instructions here

Thank you in any way.

Having a similar gRPC redefinition issue in my project, but with the Google’s Firebase library. So far, I have only got third-party library issues when working Google’s libraries, last time was with the WebRTC crashes when it failed to initialize any voice device instead of just skipping it.