#12417 closed Bugs (invalid)
Linking dynamically to boost::locale::info class on Windows fails when auto-linking is disabled
Reported by: | anonymous | Owned by: | Artyom Beilis |
---|---|---|---|
Milestone: | To Be Determined | Component: | locale |
Version: | Boost 1.61.0 | Severity: | Problem |
Keywords: | Cc: |
Description
There appears to be a name-mangling issue in boost::locale::info related to a public static member variable of type std::locale::id, only when linking to the DLL on Windows. When using auto-linking, there is no problem.
Setup
Boost 1.61 (tested on both pre-built and from-source libraries), Windows 10 x64, MSVC 2015 (cl 19.00.24213.1), using x64 compiler.
Code
bugtest.cc
#include <boost/locale.hpp> #include <iostream> int main() { std::locale::global(boost::locale::generator().generate("en_US.UTF-8")); std::cout << std::use_facet<boost::locale::info>(std::locale()).name() << std::endl; }
Compiler Command
cl.exe -IC:\Boost\include\boost-1_61 -DBOOST_ALL_NO_LIB -EHsc -O2 bugtest.cc -link -libpath:c:\Boost\lib boost_locale-vc140-mt-1_61.lib
Linker Failure
bugtest.obj : error LNK2019: unresolved external symbol "public: static class std::locale::id boost::locale::info::id" (?id@info@locale@boost@@2V02std@@A) referenced in function "class boost::locale::info const & cdecl std::use_facet<class boost::locale::info>(class std::locale const &)" (??$use_facet@Vinfo@locale@boost@@@std@@YAAEBVinfo@locale@boost@@AEBV20@@Z) bugtest.exe : fatal error LNK1120: 1 unresolved externals
Workaround
Force dllimport attribute
cl.exe -IC:\Boost\include\boost-1_61 -DBOOST_LOCALE_DECL=__declspec(dllimport) -DBOOST_ALL_NO_LIB -EHsc -O2 bugtest.cc -link -libpath:c:\Boost\lib boost_locale-vc140-mt-1_61.lib
Change History (3)
comment:1 by , 6 years ago
Summary: | Linking dynamically to boost::locale::info class on Windows fails when auto-linking is diasbled → Linking dynamically to boost::locale::info class on Windows fails when auto-linking is disabled |
---|
comment:2 by , 6 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 6 years ago
That's fine, but then the documentation should reflect that turning off auto-linking for DLLs on Windows is an unsupported option. I would expect it to work if linking to the correct import library.
You need to add
BOOST_ALL_DYN_LINK
orBOOST_LOCALE_DYN_LINK
definition for your windows projects when linking with DLLs so dllimport will be defined properly.It is general rule for all boost libraries.