尝试在我的代码中静态链接 boost 程序选项库时,我在链接器尝试链接它时遇到错误。
gmake[1]: Leaving directory `tools'
g++ -rdynamic -g -o test test.o -Lboost_1_39_0/lib/Linux64//libboost_program_options-gcc41-mt-1_39.a … (other dependent libs)
test.o: In function `basic_config_file_iterator':
boost_1_39_0/include/Linux64/boost-1_39/boost/program_options/detail/config_file.hpp:147: undefined reference to `boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<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)'
boost_1_39_0/include/Linux64/boost-1_39/boost/program_options/detail/config_file.hpp:150: undefined reference to `boost::program_options::detail::common_config_file_iterator::get()'
test.o: In function `boost::eof_iterator<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> >::increment()':
boost_1_39_0/include/Linux64/boost-1_39/boost/program_options/eof_iterator.hpp:75: undefined reference to `boost::program_options::detail::common_config_file_iterator::get()'
test.o: In function `boost::program_options::detail::basic_config_file_iterator<char>::getline(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
boost_1_39_0/include/Linux64/boost-1_39/boost/program_options/detail/config_file.hpp:163: undefined reference to `boost::program_options::to_internal(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: ld returned 1 exit status
gmake: *** [test] Error 1
另外,当我对这些函数的 libboost_program_options-gcc41-mt-1_39.a 进行 NM 时,我得到低于输出
$ nm -goC libboost_program_options-gcc41-mt-1_39.a | grep -i common_config_file_iterator
libboost_program_options-gcc41-mt-1_39.a:config_file.o:00000000000002e0 T boost::program_options::detail::common_config_file_iterator::add_option(char const*)
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000eb0 T boost::program_options::detail::common_config_file_iterator::get()
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 W boost::program_options::detail::common_config_file_iterator::getline(std::string&)
libboost_program_options-gcc41-mt-1_39.a:config_file.o:00000000000007f0 T boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::string, std::less<std::string>, std::allocator<std::string> > const&, bool)
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000b80 T boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::string, std::less<std::string>, std::allocator<std::string> > const&, bool)
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 W boost::program_options::detail::common_config_file_iterator::~common_config_file_iterator()
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 W boost::program_options::detail::common_config_file_iterator::~common_config_file_iterator()
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000060 T boost::program_options::detail::common_config_file_iterator::allowed_option(std::string const&) const
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 V typeinfo for boost::eof_iterator<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> >
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 V typeinfo for boost::iterator_facade<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> const, boost::forward_traversal_tag, boost::program_options::basic_option<char> const&, long>
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 V typeinfo for boost::program_options::detail::common_config_file_iterator
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 V typeinfo name for boost::eof_iterator<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> >
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 V typeinfo name for boost::iterator_facade<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> const, boost::forward_traversal_tag, boost::program_options::basic_option<char> const&, long>
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 V typeinfo name for boost::program_options::detail::common_config_file_iterator
libboost_program_options-gcc41-mt-1_39.a:config_file.o:0000000000000000 V vtable for boost::program_options::detail::common_config_file_iterator
libboost_program_options-gcc41-mt-1_39.a:parsers.o: U boost::program_options::detail::common_config_file_iterator::get()
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 W boost::program_options::detail::common_config_file_iterator::getline(std::string&)
libboost_program_options-gcc41-mt-1_39.a:parsers.o: U boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::string, std::less<std::string>, std::allocator<std::string> > const&, bool)
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 W boost::program_options::detail::common_config_file_iterator::~common_config_file_iterator()
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 W boost::program_options::detail::common_config_file_iterator::~common_config_file_iterator()
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 W boost::program_options::detail::common_config_file_iterator::~common_config_file_iterator()
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 V typeinfo for boost::eof_iterator<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> >
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 V typeinfo for boost::iterator_facade<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> const, boost::forward_traversal_tag, boost::program_options::basic_option<char> const&, long>
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 V typeinfo for boost::program_options::detail::common_config_file_iterator
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 V typeinfo name for boost::eof_iterator<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> >
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 V typeinfo name for boost::iterator_facade<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> const, boost::forward_traversal_tag, boost::program_options::basic_option<char> const&, long>
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 V typeinfo name for boost::program_options::detail::common_config_file_iterator
libboost_program_options-gcc41-mt-1_39.a:parsers.o:0000000000000000 V vtable for boost::program_options::detail::common_config_file_iterator
我不希望在我的测试程序中使用动态绑定,因此如果我在进行链接时缺少要包含的任何库,则需要任何指针。