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-generatedmain()function in your code. You can then use theBOOST_AUTO_TEST_CASEmacro for the actual tests (as many times as you like):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.