尝试在我的代码中静态链接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
我不想在我的测试程序中使用动态绑定,所以如果我在执行链接时缺少要包含的库,那么任何指针。
答案 0 :(得分:0)
问题是我链接到我的程序的方式。我在做如下
g++ -g test.cxx -o test -L/<path>/boost_1_39_0/lib/Linux64//libboost_program_options-gcc41-mt-1_39.a
而我们需要做如下
g++ -g test.cxx -o test /<path>/boost_1_39_0/lib/Linux64//libboost_program_options-gcc41-mt-1_39.a
这将解决问题。
-Abhinav
答案 1 :(得分:0)
您使用编译器开关 -L 错误。在gcc -L 中用于指定要搜索库的目录。但是,这意味着如果您没有在附加标志 -l </ strong>之后指定库名称,它将无法链接该库以形成您想要的可执行文件。
所以,在这种情况下,你会做类似的事情:
g++ -g test.cxx -o test -L/<path>/boost_1_39_0/lib/Linux64/ -lboost_program_options-gcc41-mt-1_39