/ usr / bin / ld:错误:找不到-lboost_unit_test_framework [英] /usr/bin/ld: error: cannot find -lboost_unit_test_framework

查看:4043
本文介绍了/ usr / bin / ld:错误:找不到-lboost_unit_test_framework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个标题有很多问题,但我发现没有答案为我工作...

Many questions have been asked with this title, but I found no answers working for me...

我有以下代码:

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Hello
#include <boost/test/unit_test.hpp>

int add(int i, int j)
{
    return i + j;
}

BOOST_AUTO_TEST_CASE(universeInOrder)
{
    BOOST_CHECK(add(2, 2) == 4);
}

我可以编译:

g++ -ohello -lboost_unit_test_framework hello.cpp

我得到的错误:

g++ -ohello -lboost_unit_test_framework hello.cpp
/usr/bin/ld: error: cannot find -lboost_unit_test_framework
/tmp/ccI94F8l.o:hello.cpp:function init_unit_test(): error: undefined reference to 'boost::unit_test::framework::master_test_suite()'
/tmp/ccI94F8l.o:hello.cpp:function main: error: undefined reference to 'boost::unit_test::unit_test_main(bool (*)(), int, char**)'
/tmp/ccI94F8l.o:hello.cpp:function universeInOrder::test_method(): error: undefined reference to 'boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)'
/tmp/ccI94F8l.o:hello.cpp:function universeInOrder::test_method(): error: undefined reference to 'boost::test_tools::tt_detail::check_impl(boost::test_tools::predicate_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
/tmp/ccI94F8l.o:hello.cpp:function __static_initialization_and_destruction_0(int, int): error: undefined reference to 'boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, unsigned long)'
/tmp/ccI94F8l.o:hello.cpp:function boost::unit_test::unit_test_log_t::unit_test_log_t(): error: undefined reference to 'vtable for boost::unit_test::unit_test_log_t'
/tmp/ccI94F8l.o:hello.cpp:function boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>): error: undefined reference to 'boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char const>)'
/tmp/ccI94F8l.o:hello.cpp:function boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>): error: undefined reference to 'boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&)'
/tmp/ccI94F8l.o:hello.cpp:function boost::unit_test::unit_test_log_t::~unit_test_log_t(): error: undefined reference to 'vtable for boost::unit_test::unit_test_log_t'
collect2: ld returned 1 exit status

简单示例来自 http://www.alittlemadness.com/2009/03/31 / c-unit-testing-with-boosttest / 我也遇到了这个问题与另一个大项目,在其他机器上工作正常...一些必须是错误的我的机器配置,但我没有线索(或如何调试它。)

Simple example comes from http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/ I am also experiencing this problem with another big project, that works fine on other machines... Something must be wrong with my machine configuration, but I have no clue what (or how to debug it!).

我已经做了一些事情:

检查libc.conf:

Check libc.conf:

$ cat /etc/ld.so.conf.d/libc.conf
# libc default configuration
/usr/local/lib

检查boost文件是否可以作为用户读取: p>

Check if boost file can be read as a user:

$ test -r /usr/local/lib/libboost_unit_test_framework.a && echo ok
ok

$ ll /usr/local/lib/libboost_program_options.a
-rw-r--r-- 1 root root 1.2M May 22  2013 /usr/local/lib/libboost_program_options.a

运行ldconfig?

run ldconfig?

sudo ldconfig

g ++ -Wl, -verbose -o hello hello.cpp -lboost_unit_test_framework

g++ -Wl,--verbose -o hello hello.cpp -lboost_unit_test_framework

/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o succeeded
/usr/bin/ld: Attempt to open /tmp/ccOe343V.o succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open /lib/x86_64-linux-gnu/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open /lib/x86_64-linux-gnu/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open /lib/../lib/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open /lib/../lib/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open /usr/lib/../lib/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open /usr/lib/../lib/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open //lib/x86_64-linux-gnu/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open //lib/x86_64-linux-gnu/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open //usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open //usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open //lib/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open //lib/libboost_unit_test_framework.a failed
/usr/bin/ld: Attempt to open //usr/lib/libboost_unit_test_framework.so failed
/usr/bin/ld: Attempt to open //usr/lib/libboost_unit_test_framework.a failed
/usr/bin/ld: error: cannot find -lboost_unit_test_framework
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libm.so failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libm.a failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libm.so succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.so failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libc.so failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libc.a failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc.so succeeded
/usr/bin/ld: Attempt to open /lib/x86_64-linux-gnu/libc.so.6 succeeded
/usr/bin/ld: Attempt to open /usr/lib/x86_64-linux-gnu/libc_nonshared.a succeeded
/usr/bin/ld: Attempt to open /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so succeeded
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.so failed
/usr/bin/ld: Attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a succeeded
/tmp/ccOe343V.o:hello.cpp:function init_unit_test(): error: undefined reference to 'boost::unit_test::framework::master_test_suite()'
/tmp/ccOe343V.o:hello.cpp:function main: error: undefined reference to 'boost::unit_test::unit_test_main(bool (*)(), int, char**)'
/tmp/ccOe343V.o:hello.cpp:function universeInOrder::test_method(): error: undefined reference to 'boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)'
/tmp/ccOe343V.o:hello.cpp:function universeInOrder::test_method(): error: undefined reference to 'boost::test_tools::tt_detail::check_impl(boost::test_tools::predicate_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
/tmp/ccOe343V.o:hello.cpp:function __static_initialization_and_destruction_0(int, int): error: undefined reference to 'boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, unsigned long)'
/tmp/ccOe343V.o:hello.cpp:function boost::unit_test::unit_test_log_t::unit_test_log_t(): error: undefined reference to 'vtable for boost::unit_test::unit_test_log_t'
/tmp/ccOe343V.o:hello.cpp:function boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>): error: undefined reference to 'boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char const>)'
/tmp/ccOe343V.o:hello.cpp:function boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>): error: undefined reference to 'boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&)'
/tmp/ccOe343V.o:hello.cpp:function boost::unit_test::unit_test_log_t::~unit_test_log_t(): error: undefined reference to 'vtable for boost::unit_test::unit_test_log_t'
collect2: ld returned 1 exit status


推荐答案


我的机器配置必须出错,但我不知道是什么(或如何调试它)

Something must be wrong with my machine configuration, but I have no clue what (or how to debug it!)

尝试,

g++ -Wl,--verbose -o hello hello.cpp -lboost_unit_test_framework

,然后查找表示:尝试打开... boost_unit_test_framework 。它将更好地了解链接器用来尝试定位所讨论的静态或动态库的搜索路径。

and look for the lines saying: attempt to open ... boost_unit_test_framework. It will give you a better idea for the search paths the linker employs to try and locate the static or dynamic library in question.

这篇关于/ usr / bin / ld:错误:找不到-lboost_unit_test_framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆