c++ - 链接问题 tinylibxml C++ Ubuntu

标签 c++ ubuntu tinyxml

当我尝试执行简单的 tinylibxml 程序时出现错误。

操作系统 -> Ubuntu 集成开发环境 -> 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 和更多文件。 你们能不能指导我如何做到这一点。

谢谢

最佳答案

构建时你需要做类似的事情

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

这应该生成 mycode.o

你现在需要做的是:

g++ -o mycode -ltinyxml mycode.o

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

对于简单的东西,您可以一步编译和链接,但对于更复杂的东西,您需要将这些步骤分开。

所有这些都可以使用 makeMakefile

自动完成

看看The GCC Manual有关编译器选项的更多信息。

关于c++ - 链接问题 tinylibxml C++ Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4346535/

相关文章:

C++析构函数提前调用

c++ - 是否可以使用 Visual Studio 6.0(VC98 编译器)构建使用 list 指定依赖项的应用程序?

ubuntu - 在 Ubuntu 12.04 上的 Nginx 中设置 iRedMail 管理站点

ubuntu - 如何修复 'Failed to initialize end point associated with ProtocolHandler' 错误?

c++ - 在 C++ 中使用 tiny xml 进行 xml 解析的问题?

c++ - 如何在 TinyXML2 中将 XMLElement 转换为字符串

c++ - QML ListView 从 mysql 数据库中检索数据

c++ - MPI_Scatterv 中的 displs 参数是什么?

linux - Ubuntu 无法挂载 Windows 硬盘驱动器,即使 Windows 在双启动时正确关闭

c++ - 使用 TinyXML 获取段错误