0

I am trying to run this example (from: https://theboostcpplibraries.com/boost.serialization-archive#ex.serialization_01):

#include <boost/archive/text_oarchive.hpp>
#include <iostream>

using namespace boost::archive;

int main()
{
  text_oarchive oa{std::cout};
  int i = 1;
  oa << i;
}

With the command:

gcc -L"/usr/local/include/" test.cpp

And I am getting the following back:

Undefined symbols for architecture x86_64:
  "boost::locale::base_message_format<char>::id", referenced from:
      boost::locale::basic_message<char>::write(std::__1::locale const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const in test-e8c2b0.o
  "boost::locale::details::format_parser::get_position()", referenced from:
      boost::locale::basic_format<char>::format_output(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in test-e8c2b0.o
  "boost::locale::details::format_parser::set_one_flag(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&)", referenced from:
      boost::locale::basic_format<char>::format_output(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in test-e8c2b0.o
  "boost::locale::details::format_parser::restore()", referenced from:
      boost::locale::basic_format<char>::format_guard::restore() in test-e8c2b0.o
  "boost::locale::details::format_parser::format_parser(std::__1::ios_base&, void*, void (*)(void*, std::__1::locale const&))", referenced from:
      boost::locale::basic_format<char>::format_output(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in test-e8c2b0.o
  "boost::locale::details::format_parser::~format_parser()", referenced from:
      boost::locale::basic_format<char>::format_output(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in test-e8c2b0.o
  "boost::locale::ios_info::display_flags(unsigned long long)", referenced from:
      boost::locale::as::number(std::__1::ios_base&) in test-e8c2b0.o
      boost::locale::as::currency(std::__1::ios_base&) in test-e8c2b0.o
      boost::locale::as::date(std::__1::ios_base&) in test-e8c2b0.o
      boost::locale::as::time(std::__1::ios_base&) in test-e8c2b0.o
      boost::locale::as::strftime(std::__1::ios_base&) in test-e8c2b0.o
  "boost::locale::ios_info::date_time_pattern_set()", referenced from:
      void boost::locale::ios_info::date_time_pattern<char>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in test-e8c2b0.o
  "boost::locale::ios_info::get(std::__1::ios_base&)", referenced from:
      boost::locale::as::number(std::__1::ios_base&) in test-e8c2b0.o
      boost::locale::as::currency(std::__1::ios_base&) in test-e8c2b0.o
      boost::locale::as::date(std::__1::ios_base&) in test-e8c2b0.o
      boost::locale::as::time(std::__1::ios_base&) in test-e8c2b0.o
      boost::locale::basic_format<char>::write(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in test-e8c2b0.o
      void boost::locale::details::format_parser::set_flag_with_str<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 test-e8c2b0.o
      boost::locale::as::strftime(std::__1::ios_base&) in test-e8c2b0.o
      ...
  "boost::locale::converter<char>::id", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::to_upper<char>(char const*, std::__1::locale const&) in test-e8c2b0.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::to_lower<char>(char const*, std::__1::locale const&) in test-e8c2b0.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::to_title<char>(char const*, std::__1::locale const&) in test-e8c2b0.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::fold_case<char>(char const*, std::__1::locale const&) in test-e8c2b0.o
  "boost::locale::generator::generator()", referenced from:
      _main in test-e8c2b0.o
  "boost::locale::generator::~generator()", referenced from:
      _main in test-e8c2b0.o
  "boost::locale::ios_info::domain_id() const", referenced from:
      boost::locale::basic_format<char>::write(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in test-e8c2b0.o
  "boost::locale::generator::generate(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
      boost::locale::generator::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in test-e8c2b0.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:
      void boost::locale::details::format_parser::set_flag_with_str<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 test-e8c2b0.o
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      void std::__1::vector<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> > >::__push_back_slow_path<boost::locale::details::formattible<char> const>(boost::locale::details::formattible<char> const&) in test-e8c2b0.o
  "std::__1::locale::has_facet(std::__1::locale::id&) const", referenced from:
      boost::locale::basic_message<char>::write(std::__1::locale const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const in test-e8c2b0.o
  "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-e8c2b0.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::to_upper<char>(char const*, std::__1::locale const&) in test-e8c2b0.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::to_lower<char>(char const*, std::__1::locale const&) in test-e8c2b0.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::to_title<char>(char const*, std::__1::locale const&) in test-e8c2b0.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::fold_case<char>(char const*, std::__1::locale const&) in test-e8c2b0.o
      boost::locale::basic_message<char>::write(std::__1::locale const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const in test-e8c2b0.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 test-e8c2b0.o
      ...
  "std::__1::ios_base::getloc() const", referenced from:
      _main in test-e8c2b0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-e8c2b0.o
      boost::locale::basic_format<char>::write(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in test-e8c2b0.o
      boost::locale::basic_format<char>::imbue_locale(void*, std::__1::locale const&) in test-e8c2b0.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 test-e8c2b0.o
  "std::logic_error::logic_error(char const*)", referenced from:
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
  "std::length_error::~length_error()", referenced from:
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
      _main in test-e8c2b0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(unsigned long, char)", referenced from:
      std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in test-e8c2b0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(char const*)", referenced from:
      boost::locale::basic_message<char>::str(std::__1::locale const&, int) const in test-e8c2b0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long)", referenced from:
      boost::locale::details::string_cast_traits<char>::cast(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in test-e8c2b0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::push_back(char)", referenced from:
      boost::locale::basic_format<char>::format_output(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in test-e8c2b0.o
      boost::locale::details::string_cast_traits<char>::cast(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in test-e8c2b0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      boost::locale::basic_format<char>::basic_format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in test-e8c2b0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
      _main in test-e8c2b0.o
      boost::locale::basic_format<char>::~basic_format() in test-e8c2b0.o
      boost::locale::basic_message<char>::~basic_message() in test-e8c2b0.o
      boost::locale::basic_format<char>::basic_format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in test-e8c2b0.o
      boost::locale::basic_format<char>::write(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in test-e8c2b0.o
      boost::locale::basic_message<char>::str(std::__1::locale const&, int) const in test-e8c2b0.o
      boost::locale::basic_format<char>::format_output(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in test-e8c2b0.o
      ...
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      boost::locale::basic_format<char>::write(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in test-e8c2b0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::put(char)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-e8c2b0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-e8c2b0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
      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 test-e8c2b0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()", referenced from:
      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 test-e8c2b0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(double)", referenced from:
      _main in test-e8c2b0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(long)", referenced from:
      _main in test-e8c2b0.o
      void boost::locale::details::formattible<char>::write<long>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, void const*) in test-e8c2b0.o
  "std::__1::cout", referenced from:
      _main in test-e8c2b0.o
  "std::__1::ctype<char>::id", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-e8c2b0.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 test-e8c2b0.o
  "std::__1::locale::global(std::__1::locale const&)", referenced from:
      _main in test-e8c2b0.o
  "std::__1::locale::locale(std::__1::locale const&)", referenced from:
      _main in test-e8c2b0.o
      boost::locale::basic_format<char>::imbue_locale(void*, std::__1::locale const&) in test-e8c2b0.o
  "std::__1::locale::locale()", referenced from:
      _main in test-e8c2b0.o
  "std::__1::locale::~locale()", referenced from:
      _main in test-e8c2b0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-e8c2b0.o
      boost::locale::basic_format<char>::write(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in test-e8c2b0.o
      boost::locale::basic_format<char>::imbue_locale(void*, std::__1::locale const&) in test-e8c2b0.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 test-e8c2b0.o
  "std::__1::locale::operator=(std::__1::locale const&)", referenced from:
      _main in test-e8c2b0.o
      boost::locale::basic_format<char>::imbue_locale(void*, std::__1::locale const&) in test-e8c2b0.o
  "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
      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 test-e8c2b0.o
  "std::__1::ios_base::clear(unsigned int)", referenced from:
      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 test-e8c2b0.o
  "std::__1::ios_base::imbue(std::__1::locale const&)", referenced from:
      _main in test-e8c2b0.o
      boost::locale::basic_format<char>::imbue_locale(void*, std::__1::locale const&) in test-e8c2b0.o
  "std::terminate()", referenced from:
      ___clang_call_terminate in test-e8c2b0.o
  "typeinfo for std::length_error", referenced from:
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
  "typeinfo for char", referenced from:
      void boost::locale::ios_info::string_set::set<char>(char const*) in test-e8c2b0.o
  "vtable for std::length_error", referenced from:
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "operator delete[](void*)", referenced from:
      void boost::locale::ios_info::string_set::set<char>(char const*) in test-e8c2b0.o
  "operator delete(void*)", referenced from:
      std::__1::__vector_base<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> > >::~__vector_base() in test-e8c2b0.o
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::~__split_buffer() in test-e8c2b0.o
  "operator new[](unsigned long)", referenced from:
      void boost::locale::ios_info::string_set::set<char>(char const*) in test-e8c2b0.o
  "operator new(unsigned long)", referenced from:
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
  "___cxa_allocate_exception", referenced from:
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
  "___cxa_begin_catch", referenced from:
      ___clang_call_terminate in test-e8c2b0.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 test-e8c2b0.o
      boost::locale::basic_format<char>::format_guard::~format_guard() in test-e8c2b0.o
  "___cxa_call_unexpected", referenced from:
      boost::locale::basic_message<char>::write(std::__1::locale const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const in test-e8c2b0.o
      void boost::locale::details::format_parser::set_flag_with_str<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 test-e8c2b0.o
  "___cxa_end_catch", referenced from:
      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 test-e8c2b0.o
      boost::locale::basic_format<char>::format_guard::~format_guard() in test-e8c2b0.o
  "___cxa_free_exception", referenced from:
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
  "___cxa_throw", referenced from:
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
  "___gxx_personality_v0", referenced from:
      _main in test-e8c2b0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-e8c2b0.o
      boost::locale::basic_format<char>::~basic_format() in test-e8c2b0.o
      boost::locale::basic_message<char>::~basic_message() in test-e8c2b0.o
      boost::locale::basic_format<char>::basic_format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in test-e8c2b0.o
      void std::__1::vector<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> > >::__push_back_slow_path<boost::locale::details::formattible<char> const>(boost::locale::details::formattible<char> const&) in test-e8c2b0.o
      std::__1::__split_buffer<boost::locale::details::formattible<char>, std::__1::allocator<boost::locale::details::formattible<char> >&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<boost::locale::details::formattible<char> >&) in test-e8c2b0.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Not sure why I am getting a clang error when I am using gcc and why there is an error with 86_64.

Edit: with adding the commands recommended by @walnut now I am getting:

Desktop $ gcc -L"/usr/local/include/" test.cpp -lboost_serialization -lboost_locale
ld: library not found for -lboost_serialization
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mikanim
  • 409
  • 7
  • 21
  • 1
    Are you using a Mac and your "GCC" is really just a symlink to "clang"? Apple changed from GCC to Clang at some point but kept the old application names around as aliases for the new stuff, for backwards compatibility reasons.. – Jesper Juhl Jan 21 '20 at 20:01
  • As for the errors, it seems that you forgot to link the required boost libraries. I guess here `-lboost_locale` and or `-lboost_serialization` is missing? – walnut Jan 21 '20 at 20:02
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – walnut Jan 21 '20 at 20:06
  • @JesperJuhl Yea I'm on a mac and I downloaded gcc some time ago to use for c++. I haven't used clang for c++ but it's automatically on macs. – mikanim Jan 21 '20 at 20:20
  • @walnut how do I go about adding those libraries when I linked the entire boost folder? And no, the link doesn't answer my question. – mikanim Jan 21 '20 at 20:21
  • @mikanim It does answer your question, in particular [this answer](https://stackoverflow.com/a/12574400/11941443) does. You need to not only add the path to the libraries with `-L` (as you did) but you also need to add the individual libraries with the `-l` option. Just add the options I mentioned to your compiler command after the `.cpp` files. – walnut Jan 21 '20 at 20:52
  • I am now getting a new error shown in the edit above. – mikanim Jan 21 '20 at 20:58
  • 1
    @mikanim Did you install the boost libraries on your system? Also note that your `-L` option is wrong. I think you meant this to be the `-I` option. `-I` is for include paths, `-L` is for library paths. – walnut Jan 21 '20 at 21:01
  • If the libraries are not found automatically, then you need to figure out where the `libboost_serialization.so`/`libboost_serialization.a` (or similar) is located and add its path (without filename) as `-L` option to the compiler command. Where exactly the library is depends on how you build/installed it. – walnut Jan 21 '20 at 21:06
  • Weird. I installed boost by `brew install boost`but when I search for `libboost_serialization.so`on my computer there's nothing. – mikanim Jan 21 '20 at 21:16
  • @mikanim File ending etc could be different (I don't know Mac OS well) Try searching for anything starting with `libboost_`. – walnut Jan 21 '20 at 21:40
  • I re-downloaded boost with sudo port and I have now `libboost_serialization.a` but when I run `g++ -L"/usr/local/Cellar/" test.cpp -lboost_locale -lboost_serialization`I still get that `ld: library not found for -lboost_serialization clang: error: linker command failed with exit code 1 (use -v to see invocation)` – mikanim Jan 21 '20 at 22:24
  • @mikanim The path in the `-L` option must be the full path (without file name) containing the library file. It won't be found in a subdirectory. I cannot help you any further. If you want to increase your change for an answer, then I suggest that you explain in your question exactly the steps you followed to install the libraries (and the compiler) and how and from where you invoked the compiler. Someone knowledgeable about MacOS might answer. It would also make the question less of a duplicate. – walnut Jan 21 '20 at 22:41
  • @walnut -L is the full path boost/ sits in Cellar/. – mikanim Jan 21 '20 at 23:27

0 Answers0