Boost logo

Boost :

From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2007-12-18 10:46:29


Jens Seidel <jensseidel <at> users.sf.net> writes:

>
> Hi,
>
> I would like to know why Boost's unit test framework requires that the
> user defines init_unit_test_suite(int, char**) (or with char *[]
> argument???) instead of main().

It doesn't. At least not always.
 
> I recently had again some trouble because of it:
> * It broke the general autoconf test in boost.m4 as the existance of
> a Boost library can normally easily be tested by using boost code
> in main() and not init_unit_test_suite(). (Will probably be fixed
> soon in boost.m4.)

I can't comment on this, since I am not familiar with autoconf.

> * According to http://lists.boost.org/Archives/boost/2007/05/121601.php
> linkers don't look into libraries (either static or dynamic) to
> find main so that unit tests cannot be cimpiled as shared library.

They do. On *nix platforms you can put main both in shared and static libs. On
NT only static. This was a source of inconsistency till 1.34.1, so starting
that release I've removed main from shared library builds on all platforms.
And that was the problem in post above (plus the fact that gcc prefers shared
library to static one if both exist with hte same name)

> * I noticed that Debian's Boost library doesn't work for me as main()
> is not found in the shared library (but in the static one). I found
> now beside my bug report
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=456863
> also
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=432921
> which mainly refers to the link above.

It's not a bug. It's a feature. ;) Starting 1.34.1 main() doesn't reside in
shared libs.
 
> I'm not sure whether my problem is an error in Debian's packages
> or not but I ask why is main handled differently in Boost.test?

See above.

> Wouldn't it be sufficient to ask the user simple to start
> init_unit_test_suite() from a user specified main() to make most
> problems go away?

> Maybe it would be even OK to just start
> init_unit_test_suite() in the constructor of a static variable
> (yes, I know that the initialisation order may cause trouble with
> other static data).

Jens, to be frank with you, I am not quite sure what you are complaining
about: absence of main or presence of one. In any case Boost.Test supports
what you want. In many, many cases you don't need init_.. function anymore and
boost test provides a way for users to get away without it and function main()
as well both with static and shared library usage variant of the UTF. If you
prefer to define main youself and invoke init function you can do it as well
with shared library variant. Please look for more details here:

http://www.patmedia.net/~rogeeff/html/index.html

Please let me know if there is any issues still.

Genandiy


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk