简体   繁体   English

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

[英]How to link Boost Regex C++ on Mac from Source?

I have downloaded the whole Boost source from https://www.boost.org/doc/libs/1_72_0/libs/regex/doc/html/index.html and I have the instructions of installation:我已经从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

Then I got a message that everything has been successfully installed:然后我收到一条消息,一切都已成功安装:

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

Now, I have a code where I load the Boost regex header:现在,我有一个代码,用于加载 Boost regex 标头:

#include <boost/regex.hpp>

[More code...]

And now the problem is with library linking, I have tried to compile with:现在的问题是库链接,我试图编译:

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

(Not sure if I should use -lboost_regex but that's something I found in the internet). (不确定我是否应该使用-lboost_regex但这是我在互联网上找到的)。

And this fails horribly with ...而这失败了......

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::regex_traits<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*>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(std::__1::__wrap_iter<char const*>, std::__1::__wrap_iter<char const*>, boost::re_detail_500::re_set_long<unsigned int> const*, boost::re_detail_500::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool) in readvcf-3b61f4.o
  "std::__1::basic_string<char, std::__1::char_traits<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::char_traits<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::char_traits<char>, std::__1::allocator<char> >, int, int) in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_open_paren() in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_alt() in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<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*, char const*, int) in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_set_literal(boost::re_detail_500::basic_char_set<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >&) in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_creator<char, boost::regex_traits<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::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_open_paren() in readvcf-3b61f4.o
      boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<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::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<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::char_traits<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::char_traits<char>, std::__1::allocator<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, std::__1::char_traits<char>, std::__1::allocator<char> >, int, 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*&, 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> >&, char const*, unsigned long) in readvcf-3b61f4.o
      std::__1::basic_filebuf<char, std::__1::char_traits<char> >::basic_filebuf() in readvcf-3b61f4.o
      ...

And much more.以及更多。 Up to:取决于:

      _main in readvcf-3b61f4.o
      std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_istringstream() in readvcf-3b61f4.o
      virtual thunk to std::__1::basic_istringstream<char, std::__1::char_traits<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)

I have run out of ideas and I cannot find any solution.我的想法已经用完了,我找不到任何解决方案。 Please, any help would be really appreciated!请,任何帮助将不胜感激! Thank you in advance先感谢您

You are using GCC to build a c++ program, so we get these linkage errors.您正在使用 GCC 构建 c++ 程序,因此我们会收到这些链接错误。 The g++ tool is used to build a c++ program, it automatically adds the standard library linkage for you. g++工具用于构建 c++ 程序,它会自动为您添加标准库链接。

Can be fixed by可以通过固定

  1. use g++使用 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 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. use GCC with the additional option (Strongly not recommended)使用带有附加选项的 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++ 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++

Related question: undefined reference to __cxa_end_cleanup'相关问题: 对 __cxa_end_cleanup' 的未定义引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM