mardi 29 juin 2021

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:

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:

#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).

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

Aucun commentaire:

Enregistrer un commentaire