链接问题tinylibxml C++乌班图
当我尝试执行简单的tinylibxml 程序时出现错误。
操作系统->乌班图 IDE-> e 我已经通过 apt-get install 下载了 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);
}
}
,我进行了谷歌搜索,发现我需要包含 libtinyxml.cpp 和更多文件。 你们能指导我该怎么做吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
构建时,您需要执行类似
g++ -c mycode.cpp
的操作(假设您的源文件是 mycode.cpp),这应该生成 mycode.o
您现在需要执行的操作:
g++ -o mycode -ltinyxml mycode.o
这是链接步骤。这会将编译的源文件与tinyxml 库结合起来,生成最终的可执行二进制mycode。
对于简单的东西,您可以一步编译和链接,但对于更复杂的东西,您需要将这些步骤分开。
所有这些都可以使用
make
和Makefile
自动化。请查看 GCC 手册 了解有关编译器选项的更多信息。
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 aMakefile
Take a look at The GCC Manual for more info on compiler options.
tinyxml 附带有一个 makefile,运行它来构建库,然后将该库包含在链接行中。
编辑:@doron 善意地为您提供了“链接库”的说明:)
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" :)