|
Boost Users : |
Subject: [Boost-users] program_options - example will not compile
From: Neil Sutton (neilmsutton_at_[hidden])
Date: 2013-03-12 15:35:18
I have the following:
1. */usr/local/lib/* which contains
libboost_program_options.a
libboost_program_options.so
libboost_program_options.so_1.53.0
2. /usr/local/include/boost
that contains program_options.hpp
I want to compile this file which can be found in boost
/libs/program_options/examples:
----------------------------------
// 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;
}
-----------------------------
A. g++ error. This is the command I am using with g++
g++ first.cpp -o first -L/usr/local/lib/libboost_program_options.so
and this is the error output:
------------
/tmp/cctMoqyr.o: In function `main':
first.cpp:(.text+0x1a): undefined reference to
`boost::program_options::options_description::m_default_line_length'
first.cpp:(.text+0x2a): undefined reference to
`boost::program_options::options_description::m_default_line_length'
first.cpp:(.text+0x72): undefined reference to
`boost::program_options::options_description::options_description(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&, unsigned int,
unsigned int)'
first.cpp:(.text+0xed): undefined reference to
`boost::program_options::options_description::add_options()'
first.cpp:(.text+0x10b): undefined reference to
`boost::program_options::options_description_easy_init::operator()(char
const*, char const*)'
first.cpp:(.text+0x127): undefined reference to
`boost::program_options::options_description_easy_init::operator()(char
const*, boost::program_options::value_semantic const*, char const*)'
first.cpp:(.text+0x135): undefined reference to
`boost::program_options::variables_map::variables_map()'
first.cpp:(.text+0x191): undefined reference to
`boost::program_options::store(boost::program_options::basic_parsed_options<char>
const&, boost::program_options::variables_map&, bool)'
first.cpp:(.text+0x1e6): undefined reference to
`boost::program_options::notify(boost::program_options::variables_map&)'
first.cpp:(.text+0x28b): undefined reference to
`boost::program_options::operator<<(std::basic_ostream<char,
std::char_traits<char> >&, boost::program_options::options_description
const&)'
/tmp/cctMoqyr.o: In function
`boost::program_options::error_with_option_name::~error_with_option_name()':
first.cpp:(.text._ZN5boost15program_options22error_with_option_nameD2Ev[boost::program_options::error_with_option_name::~error_with_option_name()]+0xd):
undefined reference to `vtable for
boost::program_options::error_with_option_name'
/tmp/cctMoqyr.o: In function
`boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, int)':
first.cpp:(.text._ZN5boost15program_options16validation_errorC1ENS1_6kind_tERKSsS4_i[boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, int)]+0x1d): undefined reference to
`boost::program_options::validation_error::get_template(boost::program_options::validation_error::kind_t)'
first.cpp:(.text._ZN5boost15program_options16validation_errorC1ENS1_6kind_tERKSsS4_i[boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, int)]+0x47): undefined reference to
`boost::program_options::error_with_option_name::error_with_option_name(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, int)'
/tmp/cctMoqyr.o: In function
`boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper()':
first.cpp:(.text._ZN5boost15program_options29value_semantic_codecvt_helperIcEC2Ev[boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper()]+0x16):
undefined reference to `vtable for
boost::program_options::value_semantic_codecvt_helper<char>'
/tmp/cctMoqyr.o: In function
`boost::program_options::value_semantic_codecvt_helper<char>::~value_semantic_codecvt_helper()':
first.cpp:(.text._ZN5boost15program_options29value_semantic_codecvt_helperIcED2Ev[boost::program_options::value_semantic_codecvt_helper<char>::~value_semantic_codecvt_helper()]+0xb):
undefined reference to `vtable for
boost::program_options::value_semantic_codecvt_helper<char>'
/tmp/cctMoqyr.o: In function
`boost::program_options::variables_map::operator[](std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const':
first.cpp:(.text._ZNK5boost15program_options13variables_mapixERKSs[boost::program_options::variables_map::operator[](std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const]+0x14):
undefined reference to
`boost::program_options::abstract_variables_map::operator[](std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cctMoqyr.o: In function
`boost::program_options::variables_map::~variables_map()':
first.cpp:(.text._ZN5boost15program_options13variables_mapD1Ev[boost::program_options::variables_map::~variables_map()]+0xd):
undefined reference to `vtable for boost::program_options::variables_map'
/tmp/cctMoqyr.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_parserIcEC1EiPKPKc[boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int,
char const* const*)]+0x6b): undefined reference to
`boost::program_options::detail::cmdline::cmdline(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&)'
/tmp/cctMoqyr.o: In function
`boost::program_options::basic_command_line_parser<char>::options(boost::program_options::options_description
const&)':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE7optionsERKNS0_19options_descriptionE[boost::program_options::basic_command_line_parser<char>::options(boost::program_options::options_description
const&)]+0x14): undefined reference to
`boost::program_options::detail::cmdline::set_options_description(boost::program_options::options_description
const&)'
/tmp/cctMoqyr.o: In function
`boost::program_options::basic_command_line_parser<char>::style(int)':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE5styleEi[boost::program_options::basic_command_line_parser<char>::style(int)]+0x14):
undefined reference to
`boost::program_options::detail::cmdline::style(int)'
/tmp/cctMoqyr.o: In function
`boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&>)':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE12extra_parserENS_9function1ISt4pairISsSsERKSsEE[boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&>)]+0x28): undefined
reference to
`boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&>)'
/tmp/cctMoqyr.o: In function
`boost::program_options::basic_command_line_parser<char>::run()':
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE3runEv[boost::program_options::basic_command_line_parser<char>::run()]+0x12):
undefined reference to
`boost::program_options::detail::cmdline::get_canonical_option_prefix()'
first.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE3runEv[boost::program_options::basic_command_line_parser<char>::run()]+0x3d):
undefined reference to `boost::program_options::detail::cmdline::run()'
/tmp/cctMoqyr.o: In function `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> > > >
boost::program_options::to_internal<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >
>(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&)':
first.cpp:(.text._ZN5boost15program_options11to_internalISsEESt6vectorISsSaISsEERKS2_IT_SaIS5_EE[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> > > >
boost::program_options::to_internal<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >
>(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&)]+0x3c):
undefined reference to
`boost::program_options::to_internal(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost15program_options11typed_valueIdcEE[vtable
for boost::program_options::typed_value<double, char>]+0x1c): undefined
reference to
`boost::program_options::value_semantic_codecvt_helper<char>::parse(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&, bool) const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost15program_options20invalid_option_valueE[vtable
for boost::program_options::invalid_option_value]+0x10): undefined
reference to `boost::program_options::error_with_option_name::what() const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost15program_options20invalid_option_valueE[vtable
for boost::program_options::invalid_option_value]+0x18): undefined
reference to
`boost::program_options::error_with_option_name::substitute_placeholders(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost15program_options16validation_errorE[vtable
for boost::program_options::validation_error]+0x10): undefined reference to
`boost::program_options::error_with_option_name::what() const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost15program_options16validation_errorE[vtable
for boost::program_options::validation_error]+0x18): undefined reference to
`boost::program_options::error_with_option_name::substitute_placeholders(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cctMoqyr.o:(.rodata._ZTIN5boost15program_options11typed_valueIdcEE[typeinfo
for boost::program_options::typed_value<double, char>]+0x10): undefined
reference to `typeinfo for
boost::program_options::value_semantic_codecvt_helper<char>'
/tmp/cctMoqyr.o:(.rodata._ZTIN5boost15program_options16validation_errorE[typeinfo
for boost::program_options::validation_error]+0x8): undefined reference to
`typeinfo for boost::program_options::error_with_option_name'
/tmp/cctMoqyr.o: In function `boost::program_options::typed_value<double,
char>::name() const':
first.cpp:(.text._ZNK5boost15program_options11typed_valueIdcE4nameEv[boost::program_options::typed_value<double,
char>::name() const]+0x1f): undefined reference to
`boost::program_options::arg'
/tmp/cctMoqyr.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[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)]+0xf): undefined reference to
`boost::program_options::validators::check_first_occurrence(boost::any
const&)'
first.cpp:(.text._ZN5boost15program_options8validateIdcEEvRNS_3anyERKSt6vectorISbIT0_St11char_traitsIS5_ESaIS5_EESaIS9_EEPT_l[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)]+0x92): undefined reference to
`boost::program_options::invalid_option_value::invalid_option_value(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cctMoqyr.o: In function
`boost::program_options::error_with_option_name::error_with_option_name(boost::program_options::error_with_option_name
const&)':
first.cpp:(.text._ZN5boost15program_options22error_with_option_nameC2ERKS1_[boost::program_options::error_with_option_name::error_with_option_name(boost::program_options::error_with_option_name
const&)]+0x1f): undefined reference to `vtable for
boost::program_options::error_with_option_name'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE[vtable
for
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error>
>]+0x14): undefined reference to
`boost::program_options::error_with_option_name::what() const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE[vtable
for
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error>
>]+0x1c): undefined reference to
`boost::program_options::error_with_option_name::substitute_placeholders(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE[vtable
for
boost::exception_detail::error_info_injector<boost::program_options::validation_error>]+0x10):
undefined reference to
`boost::program_options::error_with_option_name::what() const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE[vtable
for
boost::exception_detail::error_info_injector<boost::program_options::validation_error>]+0x18):
undefined reference to
`boost::program_options::error_with_option_name::substitute_placeholders(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE[vtable
for
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value>
>]+0x14): undefined reference to
`boost::program_options::error_with_option_name::what() const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE[vtable
for
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value>
>]+0x1c): undefined reference to
`boost::program_options::error_with_option_name::substitute_placeholders(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options20invalid_option_valueEEE[vtable
for
boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value>]+0x10):
undefined reference to
`boost::program_options::error_with_option_name::what() const'
/tmp/cctMoqyr.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options20invalid_option_valueEEE[vtable
for
boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value>]+0x18):
undefined reference to
`boost::program_options::error_with_option_name::substitute_placeholders(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&) const'
collect2: ld returned 1 exit status
----------------------
B. Clang error. I tried using clang instead with this command:
clang first.cpp -o first -L/usr/local/lib/libboost_program_options.so
and this is the error I get:
In file included from first.cpp:9:
In file included from /usr/local/include/boost/program_options.hpp:15:
In file included from
/usr/local/include/boost/program_options/options_description.hpp:13:
In file included from
/usr/local/include/boost/program_options/value_semantic.hpp:14:
In file included from /usr/local/include/boost/lexical_cast.hpp:151:
/usr/include/c++/4.4/cmath:518:14: error: cannot compile this builtin
function yet
return __builtin_isinf(__type(__f));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 diagnostic generated.
----------------------------
How can this be fixed?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net