在Ubuntu环境中使用C++开发时,安装了Pangolin库并成功编译了项目,但在运行时报错:

./bin/run_lidar2camera: error while loading shared libraries: libpango_windowing.so.0: cannot open shared object file: No such file or directory

这个错误提示在运行时无法找到动态库 libpango_windowing.so.0,并非编译问题。这是因为Pangolin库对应的动态库位置没有正确配置在系统的动态链接路径中。

下面是解决该问题的方法:


问题分析

这个错误表明你的程序无法找到动态库 libpango_windowing.so.0,通常是因为:

  1. Pangolin库安装后,动态库没有被配置到系统动态链接器中。
  2. 动态库存在位置,但系统的动态链接路径不包含该位置。
  3. Pangolin库没有正确安装,存在报错或动态库丢失的情况。

通过下面步骤,可以确保正确配置动态库以解决该问题。


解决步骤

1. 查找 libpango_windowing.so.0 的存在位置

使用 locate 或 find 命令查找动态库:

如果安装了 locate 工具:

locate libpango_windowing.so.0

如果没有 locate,使用 find:

find / -name "libpango_windowing.so.0" 2>/dev/null

返回路径如:

/usr/local/lib/libpango_windowing.so.0

这表示动态库存在于 /usr/local/lib。


2. 将动态库路径添加到链接器

分为两种情况:

2.1 临时添加(对当前会话有效)

通过下面命令将动态库路径添加到 LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

运行程序,确保已正确加载动态库:

./bin/run_lidar2camera
2.2 永久添加(推荐)

如果常要运行该程序,可以永久将路径添加到链接器配置中:

  1. 新增配置文件:

    sudo nano /etc/ld.so.conf.d/custom-libs.conf
    
  2. 在文件中添加动态库路径,如:

    /usr/local/lib
    
  3. 保存文件,然后更新链接器配置:

    sudo ldconfig
    

重新运行程序,确保问题解决:

./bin/run_lidar2camera

3. 重新编译安装 Pangolin

如果仍然无法找到动态库,可能是 Pangolin 安装不完整。重新安装 Pangolin:

git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
make -j$(nproc)
sudo make install

重新运行程序,确保已正确安装动态库。


总结

这篇文章认真分析了 Ubuntu 中使用 Pangolin 时报错 libpango_windowing.so.0: cannot open shared object file 的原因和解决方法。通过确保动态库路径配置正确,尽量避免这种存储器指向问题。

更多推荐