Linking error VS 9.0 - General tinyXml Tips

  • Anonymous

    Anonymous - 2010-11-03

    Hi guys,
    I just started to use tinyXml because I need an xml parser for my program.
    I was wondering if I could ask you a bunch of questions about getting started.

    1) to build the library I downloaded the file from sourceforge and I built it. In my project I just have to use the 2 .h files and the lib file. Is it correct?

    2) I'm trying to compile the first example and it is working; I have one question though. If before

    #include <cstdio>
    #include "tinyxml.h"

    I try to define_ TIXML_USE_STL_ to use all the feature of stream and whatnot but I have a link error:

    unresolved external symbol "protected: virtual void __thiscall TiXmlDocument::StreamIn…

    Am I doing something wrong? Is there a solution? I would really like to use streams in my project.

    Any suggestions where to start to learn this library?

    Thanks in advance to everyone.



  • Ellers

    Ellers - 2010-11-03

    The idea used to be (not sure if is still true) that TinyXML is so tiny that you put the C++ files directly in your project - no .lib required. If you didn't do that, it may well explain the unresolved symbol. Not sure though, as I haven't tried in a while and am not even sure what the .lib is!

  • Jay Lash

    Jay Lash - 2010-11-03

    I use TinyXML as a library but dont have STL turned on, sorry.

    The error indicates that the linker could not locate a body for TiXmlDocument::StreamIn.  This is because TiXmlDocument does not have an implementation for it and the base class, TiXmlNode declares it pure virtual.

    Dont know what to suggest for a solution.

  • Anonymous

    Anonymous - 2010-11-03

    Hi guys, thank you very much for the fast reply!!!

    I have just seen that the method is declared virtual (I was dumb to not check that before, my fault).

    My question is: that method makes the class an abstract class since one pure virtual method is enough to make the class abstract.

    I have just taken a look at the tinyxml.cpp file  and it doesn't define any StreamIn method. I tried defining an empty one, recompiling the libraries and try my compilation again but the I have a double definitions and a dozen of methods…
    I'm sure it is my fault since the library is really well done but I don't understand where my error is.

    Has anyone ever used the STL part of tinyXml? I ask just to know if there is someone who can help me.

    x ellers88:
    normally in a project you just include the .h files and you use the lib. I know that you can include .cpp files but that brings you to have a huge project if you need to include more than one library, that's why I have used the lib file.

    Thanks anyway to both of you guys.

    If I will come up with something I'll let you know.

  • Ellers

    Ellers - 2010-11-03

    normally in a project you just include the .h files and you use the lib. I know
    that you can include .cpp files but that brings you to have a huge project if
    you need to include more than one library, that's why I have used the lib file.

    It depends what you mean by "normal"? I agree it is conventional to link a lib, but so what? I'm simply stating the way that has been most effective - essentially embedding an XML parser in your code directly rather than linking. I'm not proposing you do that for a big library, but for one with 2 files.

    Moreover, I think it will solve your problem. I bet the lib you're linking wasn't built with the STL option turned on.

    Try putting the C++ files directly in your project. If that still fails (or out of interest) grep through the TinyXML code for StreamIn or TIXML_USE_STL - I bet something will stand out.

    If you prefer the lib approach (and naturally there are numerous benefits to that) then try rebuilding it with the STL option turned on.

  • Anonymous

    Anonymous - 2010-11-03

    I tried to compile the lib with the TIXML_USE_STL on and the lib worked (I had to write a void implementation of StreamIn method though). The problem is that when I compile my project with the TIXML_USE_STL on (you have to compile your project with this option too to enable .h file declaration) I have more than ten linking errors.

    I tried including the files and it worked. I apologise if I didn't try before. Now the question is: why the project compiles with the files but if I compile the lib file it doesn't work? (Again, with the lib file I have something like ten or more linking errors)

    Thanks for the solution, you were right about the files. I would like to use lib files and I will try again to see if there is something I can do.

  • Anonymous

    Anonymous - 2010-11-03

    If I compile the lib with the STL option on and then I include the lib in my project (with STL option on too) I have this error:

    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in tinyxmld_STL.lib(tinyxml.obj)

    ……. (I have this error for more than 10 functions)

    So what is the problem here?
    It is really weird that with the .cpp files it works but with the .lib it doesn't…

  • Ellers

    Ellers - 2010-11-03

    In project settings check C++ code generation, look at runtime library. Your lib and your project must have the same setting (multithreaded debug, or whatever). The msvcprtd gives it away.

    Though I respect your desire to have libs in an attempt at "reuse" or "good separation of concerns", I think in the case of tinyxml - as you've shown - it's a little more effort than it is worth. Easier just to stick the files in there.

  • Anonymous

    Anonymous - 2010-11-04

    Thank you very vey much, I didn't know that libraries and then projects that use them must have the same parameter.
    You really solved my problem; nad yeah, maybe the next time, if I'm going to have few files as tinyXml, I will use those directly instead of the lib or whatever.

    Just as a note to everyone else, if you have any other linking errors go in Project Properties - Linker - Input - Ignore Specific Libraries - LIBCMT.

    I do apologise because I realized now that I was looking at the old documentation on the internet instead of the one downloaded with the project. I really apologise because there I'm finding some interesting things about tinyXml and STL.

    Once again, really thank you very much.

  • Ellers

    Ellers - 2010-11-04


    Which specific old doc on the web do you mean?

  • Anonymous

    Anonymous - 2010-11-04

    On this site there is the 2.6.0 version while with the project we have the 2.6.1 version.
    Not that it changes so much I should say (In the end I found about the same information in both) but just to know.

    Thanks again, bye.


Log in to post a comment.