提问人:user541686 提问时间:3/19/2023 更新时间:3/19/2023 访问量:42
MSVC 的 Boost.Regex v1.71 链接器错误,但 Clang 不然
Boost.Regex v1.71 linker error with MSVC, but not with Clang
问:
我有这个源文件,它试图将所有 Boost.Regex 实现文件包含在一个翻译单元中(是的,我知道这不是“官方”方法):
#include <boost/regex.hpp>
#include <boost/../libs/regex/src/cpp_regex_traits.cpp>
#include <boost/../libs/regex/src/cregex.cpp>
#include <boost/../libs/regex/src/c_regex_traits.cpp>
#include <boost/../libs/regex/src/fileiter.cpp>
#include <boost/../libs/regex/src/icu.cpp>
#include <boost/../libs/regex/src/instances.cpp>
#include <boost/../libs/regex/src/internals.hpp>
#include <boost/../libs/regex/src/posix_api.cpp>
#include <boost/../libs/regex/src/regex.cpp>
#include <boost/../libs/regex/src/regex_debug.cpp>
#include <boost/../libs/regex/src/regex_raw_buffer.cpp>
#include <boost/../libs/regex/src/regex_traits_defaults.cpp>
#include <boost/../libs/regex/src/static_mutex.cpp>
#include <boost/../libs/regex/src/usinstances.cpp>
#include <boost/../libs/regex/src/w32_regex_traits.cpp>
#include <boost/../libs/regex/src/wc_regex_traits.cpp>
#include <boost/../libs/regex/src/wide_posix_api.cpp>
#include <boost/../libs/regex/src/winstances.cpp>
int main()
{
std::string s = "Boost Libraries";
boost::regex expr("\\w+\\s\\w+");
boost::regex_match(s, expr);
}
如果我随后下载 Boost v1.71 并尝试使用 VS 2022 的 x64 本机工具命令提示符构建它:
cl -DBOOST_ALL_NO_LIB=1 -EHsc -I boost_1_71_0 temp.cpp
我收到一堆链接器错误:
error LNK2019: unresolved external symbol "private: class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > & __cdecl boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::do_assign(char const *,char const *,unsigned int)" referenced in function "public: class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > & __cdecl boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::assign(char const *,char const *,unsigned int)"
error LNK2019: unresolved external symbol "public: void __cdecl boost::match_results<char const *,class std::allocator<struct boost::sub_match<char const *> > >::maybe_assign(class boost::match_results<char const *,class std::allocator<struct boost::sub_match<char const *> > > const &)" referenced in function "private: bool __cdecl boost::re_detail_107100::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::c_regex_traits<char> >::match_match(void)"
error LNK2019: unresolved external symbol "public: bool __cdecl boost::re_detail_107100::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::match(void)" referenced in function "bool __cdecl boost::regex_match<char const *,class std::allocator<struct boost::sub_match<char const *> >,char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(char const *,char const *,class boost::match_results<char const *,class std::allocator<struct boost::sub_match<char const *> > > &,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags)"
error LNK2019: unresolved external symbol "public: bool __cdecl boost::re_detail_107100::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::find(void)" referenced in function "unsigned int __cdecl boost::regex_grep<struct boost::re_detail_107100::pred1,char const *,char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(struct boost::re_detail_107100::pred1,char const *,char const *,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags)"
error LNK2019: unresolved external symbol "private: void __cdecl boost::re_detail_107100::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::construct_init(class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags)" referenced in function "public: __cdecl boost::re_detail_107100::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(char const *,char const *,class boost::match_results<char const *,class std::allocator<struct boost::sub_match<char const *> > > &,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags,char const *)"
error LNK2019: unresolved external symbol "public: bool __cdecl boost::re_detail_107100::perl_matcher<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > > > >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::find(void)" referenced in function "unsigned int __cdecl boost::regex_grep<class boost::re_detail_107100::split_pred<class std::back_insert_iterator<class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > >,char,struct std::char_traits<char>,class std::allocator<char> >,class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(class boost::re_detail_107100::split_pred<class std::back_insert_iterator<class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > >,char,struct std::char_traits<char>,class std::allocator<char> >,class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags)"
error LNK2019: unresolved external symbol "private: void __cdecl boost::re_detail_107100::perl_matcher<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > > > >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::construct_init(class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags)" referenced in function "public: __cdecl boost::re_detail_107100::perl_matcher<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > > > >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::perl_matcher<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > > > >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class boost::match_results<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > > > > > &,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags,class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >)"
error LNK2019: unresolved external symbol "public: void __cdecl boost::match_results<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> > >::maybe_assign(class boost::match_results<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> > > const &)" referenced in function "private: bool __cdecl boost::re_detail_107100::perl_matcher<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> >,struct boost::c_regex_traits<wchar_t> >::match_match(void)"
但是,如果我使用而不是 .clang-cl
cl
我似乎无法弄清楚可能缺少哪些定义。cl
clang-cl
我错过了什么?
答:
1赞
user541686
3/19/2023
#1
这些模板似乎是显式声明的,阻止编译器查看定义。extern
传递可以解决此问题。-DBOOST_REGEX_NO_EXTERNAL_TEMPLATES
评论