G ++编译项目与升压单元测试 [英] g++ project compilation with boost unit test
问题描述
我试图在Linux上编译单元测试(升压),但是编译器thows一个错误。
可能有人检查我的命令?
G ++ -o UTest ../UTest/UT1.cpp ../UTest/UT2.cpp -lboost_system -lboost_thread -lboost_unit_test_framework
错误
/usr/lib/gcc/i686-linux-gnu/4.6 /../../../ I386-Linux的GNU / crt1.o:在功能`_start ':
(+的.text为0x18):未定义引用'主'
我删除的main()
从G ++ COMAND因为使用升压单元测试
它不应该被使用。
怎么了?
PS没有单元测试项目(含的main()
)编译的罚款。在Windows做工精细也是单元测试。
更新
与问题的main()
得到解决。但是,一个新的已经诞生了。
两者 UT1.cpp
和 UT2.cpp
已列入 UTCommon.h
现在我有很多错误,如以下
错误
tmp2.cpp :(文字+ 0xd44a):`提振:: unit_test :: unit_test_log_t ::运营商的LT的多个定义;≤(升压:: unit_test :: lazy_ostream常量和放大器; )
/tmp/cc0jw8uR.o:tmp.cpp:(.text+0xd44a):首先这里定义
/tmp/cctLn9QJ.o:在函数'的boost :: test_tools :: tt_detail :: equal_impl(字符常量*,字符常量*)'
UTCommon.h
的#ifndef UT_COMMON_H
#定义UT_COMMON_H的#ifndef BOOST_TEST_MODULE
#定义BOOST_TEST_MODULE的UnitTest
#万一#如果定义(__GNUC__)及和放大器;定义(__ unix__)
#包括LT&;升压/测试/包括/ unit_test.hpp>
#elif指令定义(WIN32)
#包括LT&;升压/测试/ unit_test.hpp>
#万一#万一
最佳创建包括该文件的单独的.cpp文件升压/测试/包括/ unit_test.hpp
。这将包括pre-产生的main()
函数在code。然后,您可以用实际的测试 BOOST_AUTO_TEST_CASE
宏(多次你喜欢):
的#define BOOST_TEST_DYN_LINK //这是可选
#定义BOOST_TEST_MODULE MyTest的//指定测试模块的名称
#包括LT&;升压/测试/包括/ unit_test.hpp> //包括此获得的main()
BOOST_AUTO_TEST_CASE(my_test_1)//指定一个测试用例
{
/ *测试的东西... * /
常量静态自动有望= 12;
汽车实际= my_func,并将(); BOOST_CHECK(实际==预期);
}
此编译.cpp文件(根据需要添加在自己的code定义的所有功能,连接选项),这将成为完成所有测试并生成报告的可执行文件。
I'm trying to compile unit test (boost) on Linux but compiler thows an error. Could someone check my command?
g++ -o UTest ../UTest/UT1.cpp ../UTest/UT2.cpp -lboost_system -lboost_thread -lboost_unit_test_framework
Error
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
I removed main()
from g++ comand because it should not be used when boost unit test
is used.
What's wrong?
PS The project without unit tests (with main()
) is compiled fine. Unit tests on Windows work fine also.
Update
The issue with main()
is resolved. But a new one has born.
Both UT1.cpp
and UT2.cpp
has included UTCommon.h
and now I have lots error like the following
Error
tmp2.cpp:(.text+0xd44a): multiple definition of `boost::unit_test::unit_test_log_t::operator<<(boost::unit_test::lazy_ostream const&)'
/tmp/cc0jw8uR.o:tmp.cpp:(.text+0xd44a): first defined here
/tmp/cctLn9QJ.o: In function `boost::test_tools::tt_detail::equal_impl(char const*, char const*)'
UTCommon.h
#ifndef UT_COMMON_H
#define UT_COMMON_H
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE UnitTest
#endif
#if defined (__GNUC__) && defined(__unix__)
#include <boost/test/included/unit_test.hpp>
#elif defined (WIN32)
#include <boost/test/unit_test.hpp>
#endif
#endif
Best create a separate .cpp file that includes the file boost/test/included/unit_test.hpp
. This will include an pre-generated main()
function in your code. You can then use the BOOST_AUTO_TEST_CASE
macro for the actual tests (as many times as you like):
#define BOOST_TEST_DYN_LINK // this is optional
#define BOOST_TEST_MODULE MyTest // specify the name of your test module
#include <boost/test/included/unit_test.hpp> // include this to get main()
BOOST_AUTO_TEST_CASE(my_test_1) // specify a test case
{
/* Test something... */
const static auto expected = 12;
auto actual = my_func();
BOOST_CHECK(actual == expected);
}
Compile this .cpp file (add linker options as necessary for all the functions defined in your own code), and it will become an executable that performs all the tests and generates a report.
这篇关于G ++编译项目与升压单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!