微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从源链接 Mac 上的 Boost Regex C++?

如何解决如何从源链接 Mac 上的 Boost Regex C++?

我已经从 https://www.boost.org/doc/libs/1_72_0/libs/regex/doc/html/index.html 下载了整个 Boost 源代码并且我有安装说明:

tar -vcf boost_1_76_0.tar
./bootstrap.sh --with-toolset=clang --with-libraries=program_options,regex,filesystem,system
./b2
sudo ./b2 install

然后我收到一条消息,一切都已成功安装:

The following directory should be added to compiler include paths:

    /Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0

The following directory should be added to linker library paths:

    /Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0/stage/lib

现在,我有一个代码,用于加载 Boost 正则表达式标头:

#include <boost/regex.hpp>

[More code...]

现在的问题是库链接,我尝试编译:

gcc  -I/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0 -L/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0/stage/lib -O3 -o readvcf readvcf.cc -lboost_regex

(不确定是否应该使用 -lboost_regex,但这是我在互联网上找到的)。

这失败了......

Undefined symbols for architecture x86_64:
  "std::logic_error::what() const",referenced from:
      vtable for boost::wrapexcept<std::invalid_argument> in readvcf-3b61f4.o
      vtable for boost::wrapexcept<std::logic_error> in readvcf-3b61f4.o
  "std::runtime_error::what() const",referenced from:
      vtable for boost::wrapexcept<std::runtime_error> in readvcf-3b61f4.o
      vtable for boost::regex_error in readvcf-3b61f4.o
      vtable for boost::wrapexcept<boost::regex_error> in readvcf-3b61f4.o
  "std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char> >::compare(char const*) const",referenced from:
      char* boost::re_detail_500::re_is_set_member<char*,char,boost::regex_traits<char,boost::cpp_regex_traits<char> >,unsigned int>(char*,char*,boost::re_detail_500::re_set_long<unsigned int> const*,boost::re_detail_500::regex_data<char,boost::cpp_regex_traits<char> > > const&,bool) in readvcf-3b61f4.o
      std::__1::__wrap_iter<char const*> boost::re_detail_500::re_is_set_member<std::__1::__wrap_iter<char const*>,unsigned int>(std::__1::__wrap_iter<char const*>,std::__1::__wrap_iter<char const*>,bool) in readvcf-3b61f4.o
  "std::__1::basic_string<char,std::__1::allocator<char> >::compare(unsigned long,unsigned long,char const*,unsigned long) const",referenced from:
      unsigned int boost::re_detail_500::find_sort_Syntax<boost::re_detail_500::cpp_regex_traits_implementation<char>,char>(boost::re_detail_500::cpp_regex_traits_implementation<char> const*,char*) in readvcf-3b61f4.o
      boost::re_detail_500::lookup_default_collate_name(std::__1::basic_string<char,std::__1::allocator<char> > const&) in readvcf-3b61f4.o
  "std::__1::__vector_base_common<true>::__throw_length_error() const",referenced from:
      VCF2SNP(std::__1::basic_string<char,std::__1::allocator<char> >,int,int) in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_parser<char,boost::cpp_regex_traits<char> > >::parse_open_paren() in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_parser<char,boost::cpp_regex_traits<char> > >::parse_alt() in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_parser<char,boost::cpp_regex_traits<char> > >::parse_perl_extension() in readvcf-3b61f4.o
      void boost::re_detail_500::named_subexpressions::set_name<char>(char const*,boost::cpp_regex_traits<char> > >::parse_set_literal(boost::re_detail_500::basic_char_set<char,boost::cpp_regex_traits<char> > >&) in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_creator<char,boost::cpp_regex_traits<char> > >::create_startmaps(boost::re_detail_500::re_Syntax_base*) in readvcf-3b61f4.o
      ...
  "std::__1::__vector_base_common<true>::__throw_out_of_range() const",referenced from:
      boost::re_detail_500::basic_regex_parser<char,boost::cpp_regex_traits<char> > >::parse_perl_extension() in readvcf-3b61f4.o
  "std::__1::__basic_string_common<true>::__throw_length_error() const",referenced from:
      boost::re_detail_500::cpp_regex_traits_char_layer<char>::init() in readvcf-3b61f4.o
      std::__1::basic_string<char,std::__1::allocator<char> > std::__1::operator+<char,std::__1::allocator<char> >(std::__1::basic_string<char,std::__1::allocator<char> > const&,std::__1::basic_string<char,std::__1::allocator<char> > const&) in readvcf-3b61f4.o
      boost::re_detail_500::cpp_regex_traits_implementation<char>::lookup_classname(char const*,char const*) const in readvcf-3b61f4.o
      boost::re_detail_500::cpp_regex_traits_implementation<char>::lookup_classname_imp(char const*,char const*) const in readvcf-3b61f4.o
      boost::re_detail_500::cpp_regex_traits_implementation<char>::error_string(boost::regex_constants::error_type) const in readvcf-3b61f4.o
      boost::re_detail_500::cpp_regex_traits_implementation<char>::lookup_collatename(char const*,char const*) const in readvcf-3b61f4.o
      boost::re_detail_500::lookup_default_collate_name(std::__1::basic_string<char,std::__1::allocator<char> > const&) in readvcf-3b61f4.o
      ...
  "std::__1::locale::has_facet(std::__1::locale::id&) const",referenced from:
      boost::re_detail_500::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in readvcf-3b61f4.o
      std::__1::basic_filebuf<char,std::__1::char_traits<char> >::basic_filebuf() in readvcf-3b61f4.o
  "std::__1::locale::use_facet(std::__1::locale::id&) const",referenced from:
      getAlleles(std::__1::basic_string<char,std::__1::vector<std::__1::vector<bool,std::__1::allocator<bool> >,std::__1::allocator<std::__1::vector<bool,std::__1::allocator<bool> > > >&,int) in readvcf-3b61f4.o
      VCF2SNP(std::__1::basic_string<char,int) in readvcf-3b61f4.o
      std::__1::basic_filebuf<char,std::__1::char_traits<char> >::imbue(std::__1::locale const&) in readvcf-3b61f4.o
      boost::re_detail_500::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in readvcf-3b61f4.o
      boost::cpp_regex_traits<char>::toi(char const*&,int) const in readvcf-3b61f4.o
      std::__1::basic_ostream<char,std::__1::char_traits<char> >& std::__1::__put_character_sequence<char,std::__1::char_traits<char> >(std::__1::basic_ostream<char,std::__1::char_traits<char> >&,unsigned long) in readvcf-3b61f4.o
      std::__1::basic_filebuf<char,std::__1::char_traits<char> >::basic_filebuf() in readvcf-3b61f4.o
      ...

还有更多。高达:

      _main in readvcf-3b61f4.o
      std::__1::basic_istringstream<char,std::__1::allocator<char> >::~basic_istringstream() in readvcf-3b61f4.o
      virtual thunk to std::__1::basic_istringstream<char,std::__1::allocator<char> >::~basic_istringstream() in readvcf-3b61f4.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command Failed with exit code 1 (use -v to see invocation)

我的想法已经用完了,我找不到任何解决方案。请,任何帮助将不胜感激!提前致谢

解决方法

您正在使用 GCC 构建 C++ 程序,因此我们会收到这些链接错误。 g++ 工具用于构建 C++ 程序,它会自动为您添加标准库链接。

可以通过

修复
  1. 使用 g++

    g++ -I/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0 -L/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0/stage/lib -O3 -o readvcf readvcf.cc -lboost_rege

  2. 使用带有附加选项的 GCC(强烈不推荐)

    gcc -x c++ -I/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0 -L/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0/stage/lib -O3 -o readvcf readvcf. cc -lboost_regex -lstdc++

相关问题:undefined reference to __cxa_end_cleanup'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。