如何让pkg-config正确识别已安装的libpcap依赖库
解决方案
你遇到的问题核心是libpcap.pc文件未被pkg-config检索到,按以下步骤依次排查即可:
- 第一步:安装实际包含.pc文件的依赖包
Debian/Ubuntu系发行版中,libpcap-dev是过渡虚拟包,libpcap.pc配置文件实际存放在libpcap0.8-dev包中,先执行安装:
安装完成后执行以下命令验证是否识别:sudo apt install libpcap0.8-devpkg-config --modversion libpcap - 第二步:补充pkg-config检索路径
如果安装后仍无法识别,大概率是armhf架构专属的pkgconfig路径未加入系统检索范围,先全局搜索文件位置:
假设搜索到的路径为sudo find / -name "libpcap.pc" 2>/dev/null/usr/lib/arm-linux-gnueabihf/pkgconfig/libpcap.pc,执行以下命令临时生效:
如需永久生效,将上述命令添加到export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig:$PKG_CONFIG_PATH~/.bashrc(对应bash shell)或~/.zshrc(对应zsh shell)文件末尾,再执行source ~/.bashrc或source ~/.zshrc生效即可。 - 第三步:手动创建配置文件(兜底方案)
如果全局搜索不到libpcap.pc文件,可手动在任意pkg-config检索路径下创建该文件,写入以下内容:
保存后即可被pkg-config正常识别。prefix=/usr exec_prefix=${prefix} libdir=${prefix}/lib/arm-linux-gnueabihf includedir=${prefix}/include Name: libpcap Description: Packet capture library Version: 1.8.1 Libs: -L${libdir} -lpcap Cflags: -I${includedir} - 项目编译临时适配方案
如果不想修改系统配置,编译umockdev项目时可直接指定libpcap的编译参数,执行configure时添加对应变量即可:
之后正常执行./configure LIBPCAP_CFLAGS="-I/usr/include" LIBPCAP_LIBS="-L/lib/arm-linux-gnueabihf -lpcap"make编译即可。
内容的提问来源于stack exchange,提问作者lucaswxp
相关产品推荐
相关产品推荐

