在boost ::文件系统上设置自定义环境,在Centos

问题描述 投票:0回答:1

Mcve是:

#include <iostream>
#include <locale>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/program_options/detail/utf8_codecvt_facet.hpp>

int main()
try
{
    std::locale defLocale{};
    auto converter = new boost::program_options::detail::utf8_codecvt_facet{};
    auto customUtf8Locale = std::locale{ defLocale, converter};
    std::locale::global(customUtf8Locale);
    
    std::cout << "Setting boost::filesystem::path::imbue locale..." << std::endl;
    boost::filesystem::path::imbue(customUtf8Locale);

    return 0;
}
catch(const std::exception& e)
{
    std::cerr << "Exception " << e.what() << std::endl;
    return 1;
}

https://godbolt.org/z/n8ag4dhez

本简单的代码与静态编译和链接的Boost 1.86编译。 我使用附属物部署我的应用程序。 假设在多个Linux发行版上没有问题的工作:Redhat Enterprise Linux(RHEL)7.9+,CentOS 7.9+,Ubuntu 18.04+,Debian 10+,Suse Linux Enterprise Server(SLES)15,Oracle Linux 8,Amazon Linux 2,Amazon Linux 2,Amazon Linux 2,Amazon Linux 2,Amazon Linux 2, Amazon Linux 2023,Alma Linux 8+,Rocky Linux 8+,Linux Mint 20+。而且我没有任何(几乎)抱怨。

问题仅出现在CentOS 7.9+上(我在VM中复制问题)。 抛出了例外,在日志中,我可以看到:

Setting boost::filesystem::path::imbue locale... Exception locale::facet::_S_create_c_locale name not valid

这是奇怪的事情,因为我的自定义语言环境是由默认构造的环境(Feeding“ c”语言名称给出相同结果)和自定义编码转换器的。我不用名称喂养任何地方。
为什么它失败了?以及我如何修复它?

我很难弄清楚这一点,因为这是在ubunbtu上建立的24.04,clang 18,然后部署在CentOS上,并设置了带有完整符号的调试会话,并且代码有点复杂。

reproducer:

docker run --rm -i -t centos:7

,然后:
c++ boost centos boost-program-options boost-filesystem
1个回答
0
投票
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* yum install -y git gcc-c++ make cmake boost boost-devel cat > test.cpp <<CPP #include <boost/filesystem.hpp> #include <boost/program_options.hpp> #include <boost/program_options/detail/utf8_codecvt_facet.hpp> #include <iostream> #include <locale> int main() try { std::locale defLocale{}; auto customUtf8Locale = std::locale( // defLocale // , new boost::program_options::detail::utf8_codecvt_facet{} // ); std::locale::global(customUtf8Locale); std::cout << "Setting boost::filesystem::path::imbue locale..." << std::endl; boost::filesystem::path::imbue(customUtf8Locale); } catch (std::exception const& e) { std::cerr << "Exception " << e.what() << std::endl; return 1; } CPP

现在建筑和跑步正常:

g++ -std=c++11 test.cpp -lboost_{system,filesystem,program_options}


您欢迎您在问题中添加信息,以突出显示您在做什么不同。
    

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.