Boost logo

Boost :

Subject: Re: [boost] static in_class constants
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2010-03-13 00:20:15


Christian Henning wrote:
> Hi there, I'm finishing up some linker problems I have with gcc. One
> area of problems seems to be static in_class constants that I have
> declared in my header file. MSVC doesn't have problem with it but gcc
> is complaining. I'm wondering how other libs in boost are dealing with
> these problems.

Christian,

FYI, I managed to compile & link with GCC 4.4 the pnm_test.cpp
with the new IO, and it runs (but test fails, what's not
important here):

...
gcc.link bin/pnm_test.test/gcc-4.4.1/debug/pnm_test
testing.capture-output bin/pnm_test.test/gcc-4.4.1/debug/pnm_test.run
====== BEGIN OUTPUT ======
Running 9 test cases...
unknown location(0): fatal error in "read_image_info_using_string":
std::exception: file_stream_device: failed to open file
unknown location(0): fatal error in "read_image_test": std::exception:
file_stream_device: failed to open file
unknown location(0): fatal error in "read_and_convert_image_test":
std::exception: file_stream_device: failed to open file
unknown location(0): fatal error in "read_view_test": std::exception:
file_stream_device: failed to open file
unknown location(0): fatal error in "read_and_convert_view_test":
std::exception: file_stream_device: failed to open file
unknown location(0): fatal error in "write_view_test": std::exception:
file_stream_device: failed to open file
unknown location(0): fatal error in "stream_test": std::exception:
file_stream_device: unexpected EOF
unknown location(0): fatal error in "dynamic_image_test":
std::exception: file_stream_device: failed to open file

*** 8 failures detected in test suite "Master Test Suite"

I had to modify Jamfile.v2 to use

<library>/boost/test//boost_unit_test_framework/<link>static

plus in #define BOOST_TEST_MAIN in pnm_test.cpp

> For instance in my new gil::io lib I define some tags in pnm_tags.hpp
> as follows:
>
> /// Defines type for image type property.
> struct pnm_image_type : property_base< uint32_t >
> {
> BOOST_STATIC_CONSTANT( type, _mono_asc = 1 ); // Monochrome ASCII encoding
> BOOST_STATIC_CONSTANT( type, _gray_asc = 2 ); // Gray level ASCII encoding
> BOOST_STATIC_CONSTANT( type, _color_asc = 3 ); // sRGB color ASCII encoding
> BOOST_STATIC_CONSTANT( type, _mono_bin = 4 ); // Monochrome binary encoding
> BOOST_STATIC_CONSTANT( type, _gray_bin = 5 ); // Gray level binary encoding
> BOOST_STATIC_CONSTANT( type, _color_bin = 6 ); // sRGB color binary encoding
> };

It looks OK to me.

I double checked and this is what preprocessor generates for me:

struct pnm_image_type : property_base< uint32_t >
{
    static const type _mono_asc = 1;
    static const type _gray_asc = 2;
    static const type _color_asc = 3;
    static const type _mono_bin = 4;
    static const type _gray_bin = 5;
    static const type _color_bin = 6;
};

Best regards,

-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org

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