Boost.test找不到主 [英] Boost.test cannot find main

查看:477
本文介绍了Boost.test找不到主的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用gcc 4.8工作,提高1.59上的Kubuntu 12.04。

I'm working with gcc 4.8, boost 1.59 on kubuntu 12.04.

我写了一个简单的main.cpp文件:

I wrote a simple main.cpp file:

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

BOOST_AUTO_TEST_CASE( foo )
{}

当我建立与这不起作用 G ++ -std = C ++ 11的main.cpp -I在/ usr /本地/ -L包括在/ usr / local / lib目录-lboost_unit_test_framework -o测试。我得到了一堆链接器错误的:

This doesn't work when I build with g++ -std=c++11 main.cpp -I/usr/local/include -L/usr/local/lib -lboost_unit_test_framework -o test . I get a bunch of linker error:

/usr/lib/x86_64-linux-gnu/crt1.o:在功能 _start':
(+的.text 0x20的):未定义引用主
/tmp/cc57ppN0.o:在功能
__ static_initialization_and_destruction_0(INT,INT):
。main.cpp中:(文字+ 0x131):未定义引用<$c$c>boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*,无符号长)
/tmp/cc57ppN0.o:在功能的boost :: unit_test :: make_test_case(升压:: unit_test :: callback0常量和放大器;,提振:: unit_test :: basic_cstring):
main.cpp:(.text._ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE[_ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE]+0x6d):未定义的引用`的boost :: unit_test :: test_case :: test_case(升压:: unit_test :: basic_cstring,提振:: unit_test :: callback0常量和放大器;)
collect2:ERREUR:LD Aretourné1 code政变D'执行

/usr/lib/x86_64-linux-gnu/crt1.o: In function _start': (.text+0x20): undefined reference to 'main' /tmp/cc57ppN0.o: In function__static_initialization_and_destruction_0(int, int)': main.cpp:(.text+0x131): undefined reference to boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, unsigned long)' /tmp/cc57ppN0.o: In functionboost::unit_test::make_test_case(boost::unit_test::callback0 const&, boost::unit_test::basic_cstring)': main.cpp:(.text._ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE[_ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE]+0x6d): undefined reference to `boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring, boost::unit_test::callback0 const&)' collect2: erreur: ld a retourné 1 code d'état d'exécution

这是什么未定义引用主表示?嗯,我知道,那是因为它找不到的main()但是为什么呢?据我所知我的文件的语法是正确的。它应该链接,不是吗​​?

What does undefined reference to 'main' means??? Well, I know that it is because it could not find main() but why? AFAIK the syntax of my file is correct. It should link, no?

谢谢如果你知道哪里出了问题!

Thanks if you know where the problem is!

推荐答案

OK,我找到了解决办法!

OK, I found the solution!

看来,既然1.34.1,boost.test的不再包含main()的动态(的.so)版本的。请参见这里。所以我想用静态链接,我还了解到, GCC prefers在静态的相同名称的动态库!。因此,我改变了我的编译命令为:

It seems that, since 1.34.1, boost.test no longer contains main() in dynamic (.so) version. See here. So I wanted to link with the static and I also learned that gcc prefers the dynamic libraries over the static ones for the same name!. Thus, I changed my compile command to:

G ++ -std = C ++ 11的main.cpp -I在/ usr /本地/ -L包括在/ usr / local / lib目录-lboost_unit_test_framework -static -o测试

...它工作得很好!

...and it worked fine!

我也有两个文件,​​测试... 的main.cpp test1.cpp 和运行正确执行所有的测试用例。

I also tested with two files ... main.cpp test1.cpp and the run executed all the test cases correctly.

感谢您,我希望这可以帮助别人!

Thank you, I hope this can help someone else!

这篇关于Boost.test找不到主的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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