[xsd-users] xml_schema::exception, linux, shared libraries, and visibility=hidden

Boris Kolpackov boris at codesynthesis.com
Wed Apr 21 08:54:57 EDT 2010


Hi Greg,

Greg Carter <greg at permedia.ca> writes:

> I'm having a problem catching exceptions of type xml_schema::exception  
> thrown from a shared library on linux.
>
> My shared libs look like:
> libxmlbase.so  - XSD generated code
> libmyxml.so - XSD generated code
> libmylib.so uses above libs, compiled with visibility=hidden
> myapp
>
> Code inside libmyxml.so throws:
>
> throw ::xsd::cxx::tree::unexpected_element < char > (
>      n.name (),
>      n.namespace_ (),
>      "tcfFile",
>      "http://www.geocosm.net/200608/TcfSchema");
>
> Stepping into the above constructor I end up in  
> libxsd/xsd/cxx/tree/exceptions.txx line 106, executing in libxmlbase.so. 
>
> My catch code in libmylib.so looks like:
>
> catch (const xml_schema::exception& e)
>            {
>                cout << "XML exception reading file: " << tcfFile << endl;
>                cout << e << endl;
>            }
>
> The problem is that on linux when libmylib is compiled with  
> visibility=hidden I never get into the catch, I do if I compile libmylib  
> with visibility=default.  With visibility=hidden I fall through to
> catch (std::exception& ex)
>    {
>        cout << ex.what() << endl;
>    }
> which is in myapp.
>
> I'm thinking that export defines used for the XSD generated code (XSD  
> option --export-symbol) may need to be extended to the exception types  
> so this works correctly on linux (example #define MYXSDEXPORT  
> __attribute__ ((__visibility__("default"))) ).

This is already done when you generate the XML Schema namespace into
a separate file (--generate-xml-schema option) and specify the
--export-xml-schema and --export-symbol options, as in:

xsd cxx-tree --generate-xml-schema --export-xml-schema --export-symbol \
SCHEMA_EXPORT xml-schema.xsd

The xml-schema.hxx file then contains:

template class SCHEMA_EXPORT exception< char >;

So I believe your setup should work provided that:

1. the XML Schema namespace was compiled as above and
2. all other schemas are compiled with --extern-xml-schema to use 
   xml-schema.hxx and
3. SCHEMA_EXPORT is set to visibility=default when building all the
   libraries.

Can you check that the above conditions are met in your setup? If that's
the case, then it would be helpful if you could create a small test case
that reproduces this problem.

As a side node, we are about to start final testing for XSD 3.3.0 so if 
there is indeed a problem here and you would like to have it resolved in
3.3.0, we need to move fast with this.

Boris



More information about the xsd-users mailing list