Re: [xml] Re: LibXML2 troubles compiling into MSVC



Igor Zlatkovic wrote:

You are writing a C++ program. You also use the Standard Template Library.
STL has a template class called 'list' which implements a controlled
sequence known as double-linked list. You included the standard header
<list> before you included libxml/valid.h. This caused the identifier 'list'
to be known to the compiler, as a class template, at the time it parses
libxml/valid.h.

IIRC, according to the C++ standard any STL data structure must reside in
the std namespace. An STL list is therefore refered to as std::list, so
there should be no name collisions (unless you use the 'using' operand,
or your C++ vendor forgot to make their compiler C++ compliant :)

Include the standard header <list> after you include libxml headers and you
should be set.

Although this may solve the problem for MSVC, it is not generally
applicable. For example, with the Sun Workshop 5.0 compiler you have
to include STL header before you include any other standard headers
(and libxml includes standard headers). Fortunately, Workshop correctly
uses the std namespace for STL.

I can think of two alternative solutions.

 1. Wrap your STL headers in the std namespace on MSVC (I have not
    tested that this works with MSVC)

    #if defined(_MSC_VER)
    namespace std {
    #endif
    #include <list>
    #if defined(_MSC_VER)
    }
    #endif

 2. Change the variable names in the libxml headers to be C++ and STL
    clean. Although this is a royal PITA, it may be the most portable
    solution. For more information about what C++ names to avoid, see

      http://www.oakroadsystems.com/tech/cppredef.htm



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]