内容简介:-l参数是错误的摆脱lib预修复并使用-lboost_program_options.链接器希望所有的库以lib开始,并且在指定库时要关闭它.您还可以在文件列表中包含文件库的完整路径,而不包含-l(例如,g multiple_sources.cpp /usr/lib/libboost_program_options.so),但对于系统库,最好遵循约定;它们并不总是安装在/usr/lib中.
在我的电脑上编译.我正在运行Xubuntu Lucid Lynx全面更新.
它将使用g -c multiple_sources.cpp编译没有问题,但是当我尝试链接并使用gulti_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)' ...
等等恶心.
我有图书馆安装:
>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之前的-l
他们都失败了,变化如下:
/usr/bin/ld: cannot find -llibboost_program_options.so collect2: ld returned 1 exit status
我究竟做错了什么?
-l参数是错误的摆脱lib预修复并使用-lboost_program_options.
链接器希望所有的库以lib开始,并且在指定库时要关闭它.
您还可以在文件列表中包含文件库的完整路径,而不包含-l(例如,g multiple_sources.cpp /usr/lib/libboost_program_options.so),但对于系统库,最好遵循约定;它们并不总是安装在/usr/lib中.
http://stackoverflow.com/questions/3355372/cannot-find-c-library-when-linking-error-compliling-the-boostprogram-optio
以上所述就是小编给大家介绍的《链接时找不到C库,错误编译`boost :: program_options`的例子》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。