We've just switched from our own Boost compilation to vcpkg's one (1.73.0), with the automatic vcpkg integration with Visual Studio. We are not using CMake.
Everything was compiling fine but some projects using Boost.Test, more specifically with linker errors like:
boost_unit_test_framework-vc140-mt-gd.lib(boost_unit_test_framework-vc141-mt-gd-x32-1_73.dll) : error LNK2005: "public: static class boost::unit_test::unit_test_log_t & __cdecl boost::unit_test::unit_test_log_t: :instance(void)" (?instance@unit_test_log_t@unit_test@boost@@SAAAV123@XZ) already defined in AAA.obj [c:\src\AAA\AAA.vcxproj]
boost_unit_test_framework-vc140-mt-gd.lib(boost_unit_test_framework-vc141-mt-gd-x32-1_73.dll) : error LNK2005: "public: virtual __thiscall boost::unit_test::lazy_ostream::~lazy_ostream(void)" (??1lazy_ostream@un it_test@boost@@UAE@XZ) already defined in AAA.obj [c:\src\AAA\AAA.vcxproj]
I've checked several questions and other issue reports (like this one) but all described there seems OK:
- Correct triplet (x86-windows)
- Everything dynamic
- Correct runtime version (Multi-threaded DLL for Release, Multi-threaded Debug DLL for Debug)
- No manually linked files
I've also tried disable auto-link (BOOST_ALL_NO_LIB
), forcing dynamic libraries (BOOST_DYN_LINK
), but nothing works.
Is there anything I'm missing?
After I realized that some projects using Boost.Test were compiling successfully, I started comparing them with the failing ones, and discovered the root of the problem: the file defining the main of the test application was using the included version of the framework:
while the rest of tests were using the linked version:
Changing the header file of the main to the linked counterpart made the errors to disappear:
It was working correctly with our Boost compilation, but it is clear that vcpkg doesn't like the mix.