Keywords: UE4, error LNK2005 on linking libprotobuf

Issues

LNK2005: google::protobuf::MessageLite::AppendPartialToString already defined in libprotobuf.lib

There’re tons of LNK2005 errors on packaging project( e.g. building in Shipping mode).

webrtc.lib(message_lite.obj) : error LNK2005: "public: bool __cdecl google::protobuf::MessageLite::AppendPartialToString(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)const " (?AppendPartialToString@MessageLite@protobuf@google@@QEBA_NPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in libprotobuf.lib(message_lite.cc.obj)
webrtc.lib(message_lite.obj) : error LNK2005: "public: bool __cdecl google::protobuf::MessageLite::AppendToString(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)const " (?AppendToString@MessageLite@protobuf@google@@QEBA_NPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in libprotobuf.lib(message_lite.cc.obj)
webrtc.lib(message_lite.obj) : error LNK2005: "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl google::protobuf::MessageLite::InitializationErrorString(void)const " (?InitializationErrorString@MessageLite@protobuf@google@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in libprotobuf.lib(message_lite.cc.obj)
webrtc.lib(message_lite.obj) : error LNK2005: "public: static void __cdecl google::protobuf::internal::GenericTypeHandler<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::Merge(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)" (?Merge@?$GenericTypeHandler@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@internal@protobuf@google@@SAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAV56@@Z) already defined in libprotobuf.lib(message_lite.cc.obj)

Maybe caused by:
Your project perhaps included multiple third party libraries, and they are linked a same library(e.g. libprotobuf), and this library(libprotobuf) was saved in multiple replicas in your project or engine.
e.g.: WebRTC was included in your project, libprotobuf.lib was also included as a third party library in your plugin, then packaging project would failed with error LNK2005. Because there’s another libprotobuf.lib that was included in WebRTC.

Solution:
Make sure protobuf version match the same while protobuf was inlcuded in multiple third parties.

Version of protobuf that was included in WebRTC which is a third party of Unreal is 3.3.2.
https://github.com/protocolbuffers/protobuf/releases/tag/v3.3.2

Reference:
Compilation issues on Win10 pro x64 - VS2015/2017
https://github.com/psmoveservice/PSMoveService/issues/419

LNK2005: google::protobuf::internal::ArenaStringPtr::DestroyNoArena already defined in webrtc.lib(arenastring.obj)

Errors on building with PixelStreaming (UE 4.27) and Protobuf:

game_proto.lib(TestData.pb.cc.obj) : error LNK2005: "public: void __cdecl google::protobuf::internal::ArenaStringPtr::DestroyNoArena(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const *)" (?DestroyNoArena@ArenaStringPtr@internal@protobuf@google@@QEAAXPEBV?$basic_string@
DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in webrtc.lib(arenastring.obj)
game_proto.lib(TestData.pb.cc.obj) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl google::protobuf::internal::ArenaStringPtr::MutableNoArena(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const *
)" (?MutableNoArena@ArenaStringPtr@internal@protobuf@google@@QEAAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBV56@@Z) already defined in webrtc.lib(arenastring.obj)
libprotobuf.lib(generated_message_reflection.cc.obj) : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl google::protobuf::internal::GetEmptyString(void)" (?GetEmptyString@internal@protobuf@google@@YAAEBV?$basic_string@DU?$char_traits@D@std@@V?$
allocator@D@2@@std@@XZ) already defined in webrtc.lib(generated_message_util.obj)
libprotobuf.lib(descriptor.cc.obj) : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl google::protobuf::internal::GetEmptyString(void)" (?GetEmptyString@internal@protobuf@google@@YAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std
@@XZ) already defined in webrtc.lib(generated_message_util.obj)
libprotobuf.lib(descriptor.pb.cc.obj) : error LNK2005: "public: void __cdecl google::protobuf::internal::ArenaStringPtr::DestroyNoArena(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const *)" (?DestroyNoArena@ArenaStringPtr@internal@protobuf@google@@QEAAXPEBV?$basic_string
@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in webrtc.lib(arenastring.obj)
libprotobuf.lib(any_lite.cc.obj) : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl google::protobuf::internal::GetEmptyString(void)" (?GetEmptyString@internal@protobuf@google@@YAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@
XZ) already defined in webrtc.lib(generated_message_util.obj)
libprotobuf.lib(any_lite.cc.obj) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl google::protobuf::internal::ArenaStringPtr::MutableNoArena(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const *)" (
?MutableNoArena@ArenaStringPtr@internal@protobuf@google@@QEAAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBV56@@Z) already defined in webrtc.lib(arenastring.obj)
libprotobuf.lib(any.cc.obj) : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl google::protobuf::internal::GetEmptyString(void)" (?GetEmptyString@internal@protobuf@google@@YAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) a
lready defined in webrtc.lib(generated_message_util.obj)
libprotobuf.lib(any.cc.obj) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl google::protobuf::internal::ArenaStringPtr::MutableNoArena(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const *)" (?Muta
bleNoArena@ArenaStringPtr@internal@protobuf@google@@QEAAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBV56@@Z) already defined in webrtc.lib(arenastring.obj)

Solution:
fixed: error LNK2005 google::protobuf::internal::ArenaStringPtr::DestroyNoArena


Pouvres moutons! Si nous navions à nous défendre que du loup, nous saurions bien nous en garder. Mais qui nous gardera du berger? ― Romain Rolland