Boost logo

Boost :

From: Paul Hamilton (paul_at_[hidden])
Date: 2003-08-20 22:21:37

I have found a bug in boost/format/feed_args.hpp.

The simple declaration of a static variable in a header like this:

static int x;

Is "allowed" in GCC, but in darwin, when you try to compile this code
into a "dll" (dynamic-linking), then link using ld, ld will complain
about "common symbols not allowed with MH_DYLIB output format". This
may also be the general case with all platforms, but I haven't been
able to test this.

The correct solution for the above case is, in all headers use:

extern int x;

And in a single place in the implementation:

int x = 0;

Of course the code in feed_args.hpp doesn't even really NEED a global
variable, so as a solution (rather than try to introduce the above
complicated change just for one platform), I propose that we change the

        static const std::basic_string<Ch, Tr> emptyStr;


        const std::basic_string<Ch, Tr> emptyStr = "";

Which basically does exactly the same thing.

Here is my patch to feed_args.hpp:

------------------------ feed_args.hpp.patch ------------------------
*** feed_args.hpp Wed Aug 20 18:50:10 2003
--- Wed Aug 20 18:50:12 2003
*** 34,42 ****

     template<class Tr, class Ch> inline
     void empty_buf(BOOST_IO_STD basic_ostringstream<Ch,Tr> & os) {
! // PTH 20/8/2003 - need this to NOT be a static for certain
! // we also don't really need this to be a global variable.
! const std::basic_string<Ch, Tr> emptyStr = "";

--- 34,40 ----

     template<class Tr, class Ch> inline
     void empty_buf(BOOST_IO_STD basic_ostringstream<Ch,Tr> & os) {
! static const std::basic_string<Ch, Tr> emptyStr;
------------------------ feed_args.hpp.patch ------------------------

Paul Hamilton
pHamtec P/L - Software Makers

The information transmitted is intended only for the person or entity
to which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you
received this in error, please contact the sender and delete the
material from any computer.

Boost list run by bdawes at, gregod at, cpdaniel at, john at