On Musl-libc based systems (e.g., Alpine Linux), boost::filesystem throws a runtime exception (locale::facet::_S_create_c_locale name not valid) during path initialization if LANG or LC_ALL environment variables are missing or misconfigured.
The issue stems from default_locale() in
|
std::locale default_locale() |
|
{ |
|
#if defined(BOOST_FILESYSTEM_WINDOWS_API) |
|
std::locale global_loc = std::locale(); |
|
return std::locale(global_loc, new boost::filesystem::detail::windows_file_codecvt()); |
|
#elif defined(BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET) |
|
std::locale global_loc = std::locale(); |
|
return std::locale(global_loc, new boost::filesystem::detail::utf8_codecvt_facet()); |
|
#else // Other POSIX |
|
// ISO C calls std::locale("") "the locale-specific native environment", and this |
|
// locale is the default for many POSIX-based operating systems such as Linux. |
|
return std::locale(""); |
|
#endif |
|
} |
|
|
std::locale default_locale()
{
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
...
#elif defined(BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET)
std::locale global_loc = std::locale();
return std::locale(global_loc, new boost::filesystem::detail::utf8_codecvt_facet());
#else // Other POSIX
return std::locale(""); // 💥 Crashes here on Musl if env is invalid !!!
#endif
}
On Musl/Alpine, std::locale("") forces the C++ standard library to look up system locale files. Since Musl does not have built-in localization data generation (locale-gen), this call fails immediately with a fatal runtime error.
Suggested Solution
We need a reliable way to completely bypass std::locale("") on environment-constrained or containerized systems.
Defining BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET should compile out the std::locale("") path entirely and force-fallback to Boost's internal utf8_codecvt_facet, making path initialization fully independent of host environment variables.
On Musl-libc based systems (e.g., Alpine Linux), boost::filesystem throws a runtime exception (locale::facet::_S_create_c_locale name not valid) during path initialization if LANG or LC_ALL environment variables are missing or misconfigured.
The issue stems from default_locale() in
filesystem/src/path.cpp
Lines 1456 to 1470 in d738637
On Musl/Alpine, std::locale("") forces the C++ standard library to look up system locale files. Since Musl does not have built-in localization data generation (locale-gen), this call fails immediately with a fatal runtime error.
Suggested Solution
We need a reliable way to completely bypass std::locale("") on environment-constrained or containerized systems.
Defining BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET should compile out the std::locale("") path entirely and force-fallback to Boost's internal utf8_codecvt_facet, making path initialization fully independent of host environment variables.