clang ++编译简单的boost程序链接器命令失败

时间:2017-04-07 13:53:01

标签: c++ boost clang

我一直在关注StackOverflow和其他资源上的许多其他答案,但我无法在macOS上使用boost 1.63。简单安装boost:

./bootstrap.sh --prefix=/usr/local

./b2 cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"

现在。我只是做以下事情:

#include <boost/program_options.hpp>
namespace po = boost::program_options;

int main()
{
   // Declare the supported options.
   po::options_description desc("Allowed options");
   desc.add_options()
    ("help", "produce help message")
    ("compression", po::value<int>(), "set compression level")
   ;
}

这给了我:

clang++  \
        -g -Wall -Wextra  \
        -std=c++14  \
        -stdlib=libc++ \
        -I /usr/local/include \
        -L /usr/local/lib \
        ./src/main.cpp \
        -o ./src/tool.o

Undefined symbols for architecture x86_64:
  "boost::program_options::validators::check_first_occurrence(boost::any const&)", referenced from:
      void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, int*, long) in main-afe96c.o
  "boost::program_options::validation_error::get_template(boost::program_options::validation_error::kind_t)", referenced from:
      boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, 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&, int) in main-afe96c.o
  "boost::program_options::options_description::add_options()", referenced from:
      _main in main-afe96c.o
  "boost::program_options::options_description::m_default_line_length", referenced from:
      _main in main-afe96c.o
  "boost::program_options::options_description::options_description(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, unsigned int)", referenced from:
      _main in main-afe96c.o
  "boost::program_options::invalid_option_value::invalid_option_value(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::vector<int, std::__1::allocator<int> >*, int) in main-afe96c.o
      void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, int*, long) in main-afe96c.o
  "boost::program_options::error_with_option_name::error_with_option_name(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&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
      boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, 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&, int) in main-afe96c.o
  "boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)", referenced from:
      _main in main-afe96c.o
  "boost::program_options::options_description_easy_init::operator()(char const*, char const*)", referenced from:
      _main in main-afe96c.o
  "boost::program_options::arg", referenced from:
      boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char>::name() const in main-afe96c.o
  "boost::program_options::error_with_option_name::substitute_placeholders(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
      vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error> > in main-afe96c.o
      vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error> in main-afe96c.o
      vtable for boost::program_options::validation_error in main-afe96c.o
      vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> > in main-afe96c.o
      vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> in main-afe96c.o
      vtable for boost::program_options::invalid_option_value in main-afe96c.o
  "boost::program_options::error_with_option_name::what() const", referenced from:
      vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error> > in main-afe96c.o
      vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error> in main-afe96c.o
      vtable for boost::program_options::validation_error in main-afe96c.o
      vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> > in main-afe96c.o
      vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> in main-afe96c.o
      vtable for boost::program_options::invalid_option_value in main-afe96c.o
  "boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool) const", referenced from:
      vtable for boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char> in main-afe96c.o
  "typeinfo for boost::program_options::error_with_option_name", referenced from:
      typeinfo for boost::program_options::validation_error in main-afe96c.o
  "typeinfo for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
      typeinfo for boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char> in main-afe96c.o
  "vtable for boost::program_options::error_with_option_name", referenced from:
      boost::program_options::error_with_option_name::error_with_option_name(boost::program_options::error_with_option_name const&) in main-afe96c.o
      boost::program_options::error_with_option_name::~error_with_option_name() in main-afe96c.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
      boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper() in main-afe96c.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [annorna] Error 1

但是,添加-l boost_system不起作用。获得提升的解决方案是什么?路径错了吗?或者我还需要其他标志吗?

0 个答案:

没有答案