我正在尝试在我的电脑上编译multiple_sources.cpp。我正在运行完全更新的Xubuntu Lucid Lynx操作系统。
使用g++ -c multiple_sources.cpp
编译时没有问题,但是当我尝试链接并创建可执行文件g++ multiple_sources.o
时,出现以下错误:
multiple_sources.cpp:(.text+0x3d): undefined reference to `boost::program_options::options_description::m_default_line_length'
multiple_sources.cpp:(.text+0x87): undefined reference to `boost::program_options::options_description::options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
multiple_sources.cpp:(.text+0x15a): undefined reference to `boost::program_options::options_description::add_options()'
multiple_sources.cpp:(.text+0x17b): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, char const*)'
multiple_sources.cpp:(.text+0x193): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, char const*)'
multiple_sources.cpp:(.text+0x1af): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)'
multiple_sources.cpp:(.text+0x1eb): undefined reference to `boost::program_options::options_description::m_default_line_length'
multiple_sources.cpp:(.text+0x252): undefined reference to `boost::program_options::options_description::options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
...
< p >et cetera ad nauseum.
我已经安装了这个库:
>ls -l /usr/lib/libboost_program_options*
-rw-r--r-- 1 root root 640800 2010-03-31 21:19 /usr/lib/libboost_program_options.a
lrwxrwxrwx 1 root root 26 2010-04-09 00:57 /usr/lib/libboost_program_options-mt.a -> libboost_program_options.a
lrwxrwxrwx 1 root root 34 2010-04-09 00:57 /usr/lib/libboost_program_options-mt.so -> libboost_program_options.so.1.40.0
lrwxrwxrwx 1 root root 34 2010-04-09 00:57 /usr/lib/libboost_program_options.so -> libboost_program_options.so.1.40.0
-rw-r--r-- 1 root root 289336 2010-03-31 21:19 /usr/lib/libboost_program_options.so.1.40.0
在阅读了 g++ 手册之后,我还尝试了以下方法:
g++ -llibboost_program_options multiple_sources.cpp
g++ -llibboost_program_options.a multiple_sources.cpp
g++ -llibboost_program_options.so multiple_sources.cpp
- 并且在所有上述命令前加上
-L/usr/lib
参数
但它们都失败了,出现了各种错误变化:
/usr/bin/ld: cannot find -llibboost_program_options.so
collect2: ld returned 1 exit status
我做错了什么?