开发者

linking problem tinylibxml C++ Ubuntu

I am getting error when I try to execute the simple tinylibxml program.

OS -> Ubuntu IDE -> e I have download libtinyxml through apt-get install and included the header in my program But I am still getting error Sample code is pasted below

#include "tinyxml.h"
#define TIXML_USE_STL
#include <tinyxml.h>
void dump_to_stdout(const char* pFilename);

int main()
{
 dump_开发者_运维问答to_stdout("example1.xml");
 return 0;
}

void dump_to_stdout(const char* pFilename)
{
 TiXmlDocument doc(pFilename);
 bool loadOkay = doc.LoadFile();
 if (loadOkay)
 {
  printf("\n%s:\b", pFilename);
 }
 else
 {
  printf("Failed to load file \"%s\"\n", pFilename);
 }
}

As, I did googling, I found that I need to include libtinyxml.cpp and some more files. Could you guys , please guide me how to do that.

Thanks


when building you will need to do something like

g++ -c mycode.cpp (assuming your source file is mycode.cpp)

this should generate mycode.o

you now need to do:

g++ -o mycode -ltinyxml mycode.o

which is the linking step. This will combine your compiled source file with the tinyxml library to produce a final executable binary mycode.

For simple stuff you can compile and link in one step but for more complex stuff you need to separate the steps out.

All this can be automated using a make and a Makefile

Take a look at The GCC Manual for more info on compiler options.


There is a makefile that comes with tinyxml, run that to build the library and then include that library in your link line.

EDIT: and @doron has kindly provided you the instructions for "linking the library" :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜