I am trying to get a dummy Boost.test "hello world" program running. I found documentation here and there but obviously there is something I am missing…
Here is what I have done :
Step #1 : I installed the dependencies
sudo aptitude install libboost-test-dev
which installs both the headers (libboost-test1.54-dev
) and the binary files (libboost-test1.54.0
).
Step #2 : Creating the source file to be compiled
I have one single file called test.cpp
which contains :
#define BOOST_TEST_MODULE const_string test
#include <boost/test/unit_test.hpp>
// EOF
as was recommended in the official tutorial
Step #3 : Compilation
I compile my code by calling :
g++ test.cpp -lboost_unit_test_framework
I am not 100% sure about the option to link the library since the official tutorial does not mention it explicitly. Yet, it seems to match the library file names I have in /usr/lib
. Plus, the linker does not complain about not finding the shared object or static library files.
Which returns the following error :
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
The issue
I quite agree with the linker : I don't see any main()
function in my code… But where and how should I implement it ?
I am quite surprised because I was expecting to have to create a runner.cpp
file defining function main()
but the official boost tutorial does not mention such a thing…
This answer suggests defining the BOOST_TEST_NO_MAIN
macro, but the official boost tutorial does not mention it either. Is that the proper way of doing it ?
Could someone please give me clear step-by-step instructions on how to make my dummy "hello world" project compile ?
-I/usr/include
or something? I believe the boost test headers should provide a main for you... :hmmm: sorry it's been a while since I used boost::test, imo it's a bit over-engineeredboost/test/unit_test.hpp
which is located in/usr/include
. Hence-I/usr/include
doesn't change a thing… Out of curiosity : what is your favourite unit testing framework ? (not that I'd like to start a flamewar ! (^.^) )