2010-12-03 62 views
0

当我尝试执行简单的tinylibxml程序时出现错误。链接问题tinylibxml C++ Ubuntu

OS - > Ubuntu的 IDE - 通过>电子 我有下载libtinyxml易于得到安装 并列入我的计划 的头,但我仍然得到错误 示例代码粘贴下面

#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); 
} 
} 

由于我没有使用Google,我发现我需要包含libtinyxml.cpp和其他一些文件。 请问你们,请指导我如何做到这一点。

感谢

+4

如果添加错误消息,以及这将是有益的。添加代码时,请使用下面的格式代码按钮。它确实使它更具可读性。 – doron 2010-12-03 14:38:38

+0

你正在得到什么错误? – misha 2010-12-03 14:39:08

回答

1

建设时,你需要做这样的事情

g++ -c mycode.cpp(假设你的源文件是mycode.cpp)

这应该产生mycode.o

你现在需要要做:

g++ -o mycode -ltinyxml mycode.o

这是连接步骤。这会将您编译的源文件与tinyxml库结合起来,生成最终的可执行二进制mycode。

对于简单的东西,你可以编译和链接在一个步骤,但更复杂的东西,你需要分开步骤。

所有这一切都可以使用makeMakefile

看看The GCC Manual对编译器选项的详细信息自动化。

0

有一个makefile附带tinyxml,运行它来构建库,然后将该库包含在链接行中。

编辑:和@doron慷慨提供您“链接库”中的说明:)