Linking issues with pvector<std::string> on Windows

Lately I have used more extensively pvectorstd::string and weird linking errors started to appear on Windows only (builds on Linux and macOS are fine):

libp3dtool.lib(libp3dtool.dll) : error LNK2005: “public: __cdecl pvector<class std::basic_string<char,struct std::char_traits,class std::allocator > >::~pvector<class std::basic_string<char,struct std::char_traits,class std::allocator > >(void)” (??1?$pvector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QEAA@XZ) already defined in objectName.obj [C:\projects\cosmonium\source\build\win_amd64_panda1.11.0_py310_vc14\cosmonium_engine.cp310-win_amd64.vcxproj]
libp3dtool.lib(libp3dtool.dll) : error LNK2005: “public: void __cdecl std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class pallocator_array<class std::basic_string<char,struct std::char_traits,class std::allocator > > >::push_back(class std::basic_string<char,struct std::char_traits,class std::allocator > &&)” (?push_back@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$pallocator_array@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@@std@@QEAAX$$QEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in objectName.obj [C:\projects\cosmonium\source\build\win_amd64_panda1.11.0_py310_vc14\cosmonium_engine.cp310-win_amd64.vcxproj]
libp3dtool.lib(libp3dtool.dll) : error LNK2005: “public: void __cdecl std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class pallocator_array<class std::basic_string<char,struct std::char_traits,class std::allocator > > >::push_back(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)” (?push_back@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$pallocator_array@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@@std@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in objectName.obj [C:\projects\cosmonium\source\build\win_amd64_panda1.11.0_py310_vc14\cosmonium_engine.cp310-win_amd64.vcxproj]
Creating library C:/projects/cosmonium/source/build/win_amd64_panda1.11.0_py310_vc14/RelWithDebInfo/cosmonium_engine.cp310-win_amd64.lib and object C:/projects/cosmonium/source/build/win_amd64_panda1.11.0_py310_vc14/RelWithDebInfo/cosmonium_engine.cp310-win_amd64.exp
C:\projects\cosmonium\source\build\win_amd64_panda1.11.0_py310_vc14\RelWithDebInfo\cosmonium_engine.cp310-win_amd64.dll : fatal error LNK1169: one or more multiply defined symbols found [C:\projects\cosmonium\source\build\win_amd64_panda1.11.0_py310_vc14\cosmonium_engine.cp310-win_amd64.vcxproj]

I’m not very familiar with MSVC, but from what I remember it may be something linked to the compiler not properly inlining some template instantiation, resulting in duplicate symbols. MSVC version used is 19.16.27035.0

As a workaround I reverted to std::vector<std::string> as the list is purely internal, but that mean the allocated data won’t be tracked by Panda3D, and this list may contains lots of data sadly.

This will solve it:

#include "vector_string.h

That explicitly instantiates pvector<std::string> and defines the proper import/export symbols from the Panda DLL.

2 Likes

Thanks, that indeed did the trick!