【问题标题】:Compiling with boost regex C++使用 boost 正则表达式 C++ 编译
【发布时间】:2023-03-15 05:31:01
【问题描述】:

我以前在旧电脑上使用过 boost::regex,但现在我不知道如何使用它。

我的链接器有问题,我得到了:

||=== Build: Release in regex test (compiler: GNU GCC Compiler) ===|
C:\boost\stage\lib\libboost_regex-mgw53-mt-1_63.a(regex.o)||duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size|
C:\boost\stage\lib\libboost_regex-mgw53-mt-1_63.a(regex.o)||duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size|
C:\boost\stage\lib\libboost_regex-mgw53-mt-1_63.a(regex.o)||duplicate section `.rdata$_ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size|
C:\boost\stage\lib\libboost_regex-mgw53-mt-1_63.a(regex.o)||duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size|
C:\boost\stage\lib\libboost_regex-mgw53-mt-1_63.a(cpp_regex_traits.o)||duplicate section `.data$_ZZN5boost16cpp_regex_traitsIcE21get_catalog_name_instEvE6s_name[__ZZN5boost16cpp_regex_traitsIcE21get_catalog_name_instEvE6s_name]' has different size|
obj\Release\main.o:main.cpp:(.text$_ZNK5boost16re_detail_10630031cpp_regex_traits_implementationIcE18lookup_collatenameEPKcS4_[__ZNK5boost16re_detail_10630031cpp_regex_traits_implementationIcE18lookup_collatenameEPKcS4_]+0x80)||undefined reference to `boost::re_detail_106300::lookup_default_collate_name(std::string const&)'|
obj\Release\main.o:main.cpp:(.text$_ZN5boost16re_detail_10630018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiSsi[__ZN5boost16re_detail_10630018basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiSsi]+0x1d4)||undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'|
||error: ld returned 1 exit status|
||=== Build failed: 3 error(s), 5 warning(s) (0 minute(s), 0 second(s)) ===|

代码是这样的:

#include <boost/regex.hpp>

int main()
{
    boost::regex test("test");
    return 0;
}

我正在链接C:\boost\stage\lib\libboost_regex-mgw53-mt-1_63.a,搜索目录是C:\boost

我正在使用代码块进行编译以获取您的信息。

我用 mingw/gcc 编译或“制作”了库,实际上我尝试了很多东西......我还下载并安装了 mingw,即使我已经用代码块安装了它,并且我“制作”了我后来安装的库。 (mingw的路径设置在那里)。

【问题讨论】:

  • 看起来有冲突的编译器版本/标志。
  • @Neox,您可以使用 std::regex 代替 boost::regex。它是在 C++ 11 中添加的。
  • @sehe 你能更准确一点吗?我认为问题出在我用手动下载的 mingw 编译库,并用代码块的 mingw 编译项目。你认为这是问题所在吗?
  • @Real Fresh 据我所知,std 正则表达式的语法不一样。无论如何,我已经有一个超过 6000 行的项目,在我的旧计算机上使用 boost 正则表达式进行编码...:/
  • @RealFresh 许多编译器直到他们声称支持 c++11 数年后才包含正确的实现(这太可怕了)。我不会在中途换船。

标签: c++ boost


【解决方案1】:

我找到了解决方案,我发布它以防万一它可以帮助其他人。

问题是因为我手动下载了 MinGW 并使用它来编译库,并且我正在使用 Code Blocks 的 MinGW 编译我的程序。他们可能有不同的版本,这确实是问题所在。

【讨论】:

    猜你喜欢
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多