76525

Boost Program Options link error

Question:

I am having trouble with linking -lboost_program_options. I cannot even compile the minimum example <a href="http://www.boost.org/doc/libs/1_57_0/libs/program_options/example/first.cpp" rel="nofollow">first.cpp</a>.

Here is the cpp:

// Copyright Vladimir Prus 2002-2004. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) /* The simplest usage of the library. */ #include <boost/program_options.hpp> namespace po = boost::program_options; #include <iostream> #include <iterator> using namespace std; int main(int ac, char* av[]) { try { po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("compression", po::value<double>(), "set compression level") ; po::variables_map vm; po::store(po::parse_command_line(ac, av, desc), vm); po::notify(vm); if (vm.count("help")) { cout << desc << "\n"; return 0; } if (vm.count("compression")) { cout << "Compression level was set to " << vm["compression"].as<double>() << ".\n"; } else { cout << "Compression level was not set.\n"; } } catch(exception& e) { cerr << "error: " << e.what() << "\n"; return 1; } catch(...) { cerr << "Exception of unknown type!\n"; } return 0; }

Here is my output:

g++ -o first first.cpp -lboost_program_options /tmp/ccNDtU66.o: In function `main': first.cpp:(.text+0x6f): undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)' /tmp/ccNDtU66.o: In function `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::string const&, std::string const&, int)': first.cpp:(.text._ZN5boost15program_options16validation_errorC2ENS1_6kind_tERKSsS4_i[_ZN5boost15program_options16validation_errorC5ENS1_6kind_tERKSsS4_i]+0x2e): undefined reference to `boost::program_options::validation_error::get_template(boost::program_options::validation_error::kind_t)' first.cpp:(.text._ZN5boost15program_options16validation_errorC2ENS1_6kind_tERKSsS4_i[_ZN5boost15program_options16validation_errorC5ENS1_6kind_tERKSsS4_i]+0x4c): undefined reference to `boost::program_options::error_with_option_name::error_with_option_name(std::string const&, std::string const&, std::string const&, int)' /tmp/ccNDtU66.o: In function `boost::program_options::variables_map::operator[](std::string const&) const': first.cpp:(.text._ZNK5boost15program_options13variables_mapixERKSs[_ZNK5boost15program_options13variables_mapixERKSs]+0x1f): undefined reference to `boost::program_options::abstract_variables_map::operator[](std::string const&) const' /tmp/ccNDtU66.o: In function `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)': first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0x76): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::vector<std::string, std::allocator<std::string> > const&)' /tmp/ccNDtU66.o: In function `boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::string, std::string>, std::string const&>)': first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE12extra_parserENS_9function1ISt4pairISsSsERKSsEE[_ZN5boost15program_options25basic_command_line_parserIcE12extra_parserENS_9function1ISt4pairISsSsERKSsEE]+0x33): undefined reference to `boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::string, std::string>, std::string const&>)' /tmp/ccNDtU66.o: In function `std::vector<std::string, std::allocator<std::string> > boost::program_options::to_internal<std::string>(std::vector<std::string, std::allocator<std::string> > const&)': first.cpp:(.text._ZN5boost15program_options11to_internalISsEESt6vectorISsSaISsEERKS2_IT_SaIS5_EE[_ZN5boost15program_options11to_internalISsEESt6vectorISsSaISsEERKS2_IT_SaIS5_EE]+0x46): undefined reference to `boost::program_options::to_internal(std::string const&)' /tmp/ccNDtU66.o:(.rodata._ZTVN5boost15program_options11typed_valueIdcEE[_ZTVN5boost15program_options11typed_valueIdcEE]+0x38): undefined reference to `boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, bool) const' /tmp/ccNDtU66.o:(.rodata._ZTVN5boost15program_options20invalid_option_valueE[_ZTVN5boost15program_options20invalid_option_valueE]+0x30): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::string const&) const' /tmp/ccNDtU66.o:(.rodata._ZTVN5boost15program_options16validation_errorE[_ZTVN5boost15program_options16validation_errorE]+0x30): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::string const&) const' /tmp/ccNDtU66.o: In function `boost::program_options::typed_value<double, char>::name() const': first.cpp:(.text._ZNK5boost15program_options11typed_valueIdcE4nameEv[_ZNK5boost15program_options11typed_valueIdcE4nameEv]+0x26): undefined reference to `boost::program_options::arg' /tmp/ccNDtU66.o: In function `void boost::program_options::validate<double, char>(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, double*, long)': first.cpp:(.text._ZN5boost15program_options8validateIdcEEvRNS_3anyERKSt6vectorISbIT0_St11char_traitsIS5_ESaIS5_EESaIS9_EEPT_l[_ZN5boost15program_options8validateIdcEEvRNS_3anyERKSt6vectorISbIT0_St11char_traitsIS5_ESaIS5_EESaIS9_EEPT_l]+0x128): undefined reference to `boost::program_options::invalid_option_value::invalid_option_value(std::string const&)' /tmp/ccNDtU66.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE[_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE]+0x38): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::string const&) const' /tmp/ccNDtU66.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE[_ZTVN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE]+0x30): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::string const&) const' /tmp/ccNDtU66.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE[_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE]+0x38): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::string const&) const' /tmp/ccNDtU66.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options20invalid_option_valueEEE[_ZTVN5boost16exception_detail19error_info_injectorINS_15program_options20invalid_option_valueEEE]+0x30): undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::string const&) const' collect2: error: ld returned 1 exit status Makefile:4: recipe for target 'first' failed make: *** [first] Error 1

How do I fix this?

I am using Ubuntu 16.04, Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz

Answer1:

I noticed I used g++-4.8 and it seems that my version of boost (1.54.0) requires higher version. After I switched to g++-5 it compiles normally.

Recommend

  • Visual Studio C++ remote linux debugging add linker options
  • Boost. Handy variables_map. Taking advantage of having specified the type in the options_desctriptio
  • How can i get the document title in Office 365 JavaScript API?
  • xcode 4.3.2 process hangs
  • Xamarin - is there a way to notify Xamarin.Forms from a native project?
  • What's the essential difference between these two variadic functions?
  • std::system Exception when instantiating a singleton object
  • Getting zero results in search using elastic4s
  • RPMs for IDAS IoTAgents GE, from Fiware
  • Call a php script whenever an e-mail is received?
  • What is corresponding c++ data type to SQL numeric(18,0) data type?
  • c++ regex_replace not doing intended substitution
  • How to get data from **Realm database** using **date object**?
  • Owin Authentication and claims in asp.net how to access user data
  • Using Sax parsing to edit and write XML in VB6
  • Sending HTML Form Data to Spring REST Web Service
  • Reduction and collapse clauses in OMP have some confusing points
  • How can I sort a a table with VBA with given text condition?
  • Use of this Javascript
  • Django: Count of Group Elements
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Linq Objects Group By & Sum
  • How do I change content of ComboFieldEditor?
  • Pass value from viewmodel to script in zk
  • Can Jackson SerializationFeature be overridden per field or class?
  • Sending data from AppleScript to FileMaker records
  • MySQL WHERE-condition in procedure ignored
  • Redux, normalised entities and lodash merge
  • Weird JavaScript statement, what does it mean?
  • Do I've to free mysql result after storing it?
  • How to format a variable of double type
  • Android Studio and gradle
  • Buffer size for converting unsigned long to string
  • SQL merge duplicate rows and join values that are different
  • Error creating VM instance in Google Compute Engine
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • reshape alternating columns in less time and using less memory