Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

name conflict/ vs 2010, c++ #37

Closed
jelemans opened this issue Jul 4, 2012 · 6 comments

Comments

@jelemans
Copy link

commented Jul 4, 2012

Sorry, noob problem.

Building a 64 bit C++ app.
VS returns;

tinyxml2.cpp(372): error C2872: 'XMLDocument' : ambiguous symbol
1> could be 'c:\program files (x86)\microsoft sdks\windows\v7.0a\include\msxml.h(273) : XMLDocument'
1> or 'c:\navidentdata\navident\navident\tinyxml2.h(986) : tinyxml2::XMLDocument'

is there a way to have it ignore msxml?

TIA.

@leethomason

This comment has been minimized.

Copy link
Owner

commented Jul 5, 2012

You can use:
#define WIN32_LEAN_AND_MEAN
#include windows.h

to exclude the windows XML headers. Or this should work (although I haven't confirmed):
tinyxml2::XMLDocument

I don't know a concise solution if you are using the full windows headers and don't want to append the tinyxml2:: everywhere. I'm hoping someone else may know.

@gamaral

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2012

@jelemans You're probably importing/using the full namespace, not a good idea (on windows). I would suggest aliasing the namespace, for example:

 namespace TinyXML = tinyxml2;
 namespace TXML = tinyxml2;
 ...
 TinyXML::XMLDocument ...
 TXML::XMLDocument ...

That way it at least looks pretty. :)

@toolchainX

This comment has been minimized.

Copy link

commented Oct 5, 2012

I come across the same problem and I solved it like this, in the tinyxml2.cpp brace all the code in the namespace tinyxml2 like this:

#include "tinyxml2.h"

#if 1
#include <cstdio>
#include <cstdlib>
#include <new>
#else
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <new>
#include <stdarg.h>
#endif
namespace tinyxml2
{
    class XMLDocument;
    class XMLElement;
    class XMLAttribute;
    class XMLComment;
    class XMLNode;
    class XMLText;
    class XMLDeclaration;
    class XMLUnknown;
    class XMLPrinter;

    // the previous code in this file

}  // namespace tinyxml2
// end of the file 
@kainjow

This comment has been minimized.

Copy link
Contributor

commented Nov 8, 2012

I just came across this same issue. I used the idea from @tlh1987 by enclosing the code in the namespace.

Code compiles now on VS 2010, clang 4.1 (OS X) and gcc 4.6.3 (Linux).

@wensonsmith

This comment has been minimized.

Copy link

commented Jan 16, 2013

@kainjow It dose't work for me , I download the latest version and have added using namespace tinyxml2; to my cpp file.

Compiles on VS2010 Win7 (64Bit) , It's still report the error

@kainjow

This comment has been minimized.

Copy link
Contributor

commented Jan 16, 2013

I wouldn't use 'using namespace', kind of defeats the purpose of namespaces in the first place. Just use tinyxml2::XMLDocument, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.