Ubuntu 12.04无法安装libpugixml-dev及编译求助
Hey there, let's work through this problem together. The reason you're getting the "无法找到软件包libpugixml-dev" error is that Ubuntu 12.04 (Precise Pangolin) reached its end-of-life (EOL) years ago. Most official repositories no longer host packages for it, including libpugixml-dev. Don't worry though—we can compile pugixml from source directly, which is straightforward.
手动编译pugixml的步骤
Follow these steps to get pugixml up and running on your system:
安装编译依赖工具
首先确保你有编译软件所需的基础工具,在终端运行这条命令:sudo apt-get update && sudo apt-get install build-essential cmake获取pugixml源码
下载pugixml的最新稳定版源码包(你可以从官方代码仓库获取),下载完成后解压并进入目录:tar -xf pugixml-*.tar.gz && cd pugixml-*用CMake配置构建环境
运行CMake来设置编译环境。如果想要编译成动态库(.so文件),可以添加-DBUILD_SHARED_LIBS=ON参数;默认会编译成静态库:# 编译静态库(默认选项) cmake . # 编译动态库 cmake -DBUILD_SHARED_LIBS=ON .开始编译源码
执行make命令启动编译:make将编译好的库安装到系统
把编译完成的库和头文件安装到系统目录,让其他程序可以调用:sudo make install更新系统库缓存
最后刷新系统的库缓存,确保系统能识别新安装的库:sudo ldconfig
替代方案:直接在项目中使用pugixml
如果你不想把库安装到系统全局,也可以直接把pugixml.cpp和pugixml.hpp这两个文件复制到你的项目目录里,和自己的代码一起编译即可,无需系统级安装。
另外提个醒:Ubuntu 12.04已经不再受到官方支持,你不会再收到安全更新或新的软件包版本。如果条件允许,升级到一个仍在支持的Ubuntu版本会帮你避免更多类似的问题。
内容的提问来源于stack exchange,提问作者Sílvio Filho

