unit tests: auto tests, missing main, redef'ed init_unit_test_suite

g++3.4 - boost1.37 Hello, I have n translation units .cpp and m auto test suites spread over the n files. For e.g. file ni.cpp-------------------- #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(suite1) BOOST_AUTO_TEST_CASE(case1) BOOST_AUTO_TEST_SUITE_END() file nj.cpp-------------------- #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(suite1) BOOST_AUTO_TEST_CASE(case2) BOOST_AUTO_TEST_CASE(case3) BOOST_AUTO_TEST_SUITE_END() file nk.cpp-------------------- #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(suite2) BOOST_AUTO_TEST_CASE(case1) BOOST_AUTO_TEST_CASE(case2) BOOST_AUTO_TEST_SUITE_END() The .cpp files are compiled with -DBOOST_TEST_MAIN= AFAIU, I am then not required to provide the "init_unit_test" function nor the "main" function. I then try to link an executable: g++ -m64 -Wall -Wextra -Wsign-compare -Werror -Wno-unused -std=c++98 -pedantic -Wno-long-long -pipe -g -lboost_unit_test_framework-gcc34-mt-d-1_37 -o executable *.o but i get this: nk.o: In function `init_unit_test_suite(int, char**)': ...boost/test/unit_test_suite.hpp:188: multiple definition of `init_unit_test_suite(int, char**)' ni.o: ...boost/test/unit_test_suite.hpp:188: first defined here for each object file and /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/crt1.o(.text+0x21): In function `_start': : undefined reference to `main' Regards,

AMDG Hicham Mouline wrote:
The .cpp files are compiled with -DBOOST_TEST_MAIN=
AFAIU, I am then not required to provide the "init_unit_test" function nor the "main" function.
Only use BOOST_TEST_MAIN in one translation unit. In Christ, Steven Watanabe

-----Original Message----- AMDG
Hicham Mouline wrote:
The .cpp files are compiled with -DBOOST_TEST_MAIN=
AFAIU, I am then not required to provide the "init_unit_test_suite" function nor the "main" function.
Only use BOOST_TEST_MAIN in one translation unit.
In Christ, Steven Watanabe
Thanks. As I said in my email that crossed yours:-), I did but init_unit_test_suite(...) was still multiply defined, g++ <otherflags> -DBOOST_TEST_MAIN= -o <translationunit1.o> -c <translationunit1.cpp> g++ <otherflags> -o <translationunit2.o> -c <translationunit2.cpp> ... g++ <otherflags> -lboost_unit_test_framework-gcc34-mt-d-1_37 -o test *.o also, the main function is not found. Regards,

Hicham Mouline <hicham <at> mouline.org> writes:
As I said in my email that crossed yours, I did but init_unit_test_suite(...) was still multiply defined,
Rebuild. It should only be defined in the translation unit defining BOOST_TEST_MAIN
g++ <otherflags> -DBOOST_TEST_MAIN= -o <translationunit1.o> -c <translationunit1.cpp> g++ <otherflags> -o <translationunit2.o> -c <translationunit2.cpp> ... g++ <otherflags> -lboost_unit_test_framework-gcc34-mt-d-1_37 -o test *.o
also, the main function is not found.
Make sure you link with static library. Or add define BOOST_TEST_DYN_LINK in your compilation line and link with shared library. Gennadiy.

-----Original Message----- AMDG
Hicham Mouline wrote:
The .cpp files are compiled with -DBOOST_TEST_MAIN=
AFAIU, I am then not required to provide the "init_unit_test_suite" function nor the "main" function.
Only use BOOST_TEST_MAIN in one translation unit.
In Christ, Steven Watanabe
Thanks. As I said in my email that crossed yours:-), I did but init_unit_test_suite(...) was still multiply defined, g++ <otherflags> -DBOOST_TEST_MAIN= -o <translationunit1.o> -c <translationunit1.cpp> g++ <otherflags> -o <translationunit2.o> -c <translationunit2.cpp> ... g++ <otherflags> -lboost_unit_test_framework-gcc34-mt-d-1_37 -o test *.o
also, the main function is not found. Regards,
I have BOOST_TEST_MODULE defined as well. Now I don't get the duplicate definitions but the linker doesn't find the main function,
participants (3)
-
Gennadiy Rozental
-
Hicham Mouline
-
Steven Watanabe