libgflags.so.2.2以及glog.so编译报错 cannot open shared object file/symbol lookup error解决办法

报错信息分别是:

./curve_fitting: error while loading shared libraries: libgflags.so.2.2: cannot open shared object file: No such file or directory



./curve_fitting: symbol lookup error: /usr/local/lib/libglog.so.0: undefined symbol: _ZN6google14FlagRegistererC1ISsEEPKcS3_S3_PT_S5_

——————————————————————————————————————————
在学习《SLAM 十四讲》第六讲的过程中,学习ceres的使用,但是安装之后总是报错:

报错(1)如下:


./curve_fitting: error while loading shared libraries: libgflags.so.2.2: cannot open shared object file: No such file or directory

而且这是我编译都是通过的,而且生成了可执行文件,但是就是提醒了这个错误,
然后尝试:sudo apt-get install libglags但是还是无效,显示我已经安装过了!

报错(1)解决办法:

Step1:

 git clone https://github.com/gflags/gflags

Step2:

 cd gflags
 mkdir build
 cd build

Step3(重要):

进入build之后输入:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G"Unix Makefiles" ..

之后输入

make -j4

发现make之后给的反馈信息如下:

➜  build git:(master) make -j4
Scanning dependencies of target gflags_shared
Scanning dependencies of target gflags_nothreads_shared
[ 37%] Building CXX object CMakeFiles/gflags_nothreads_shared.dir/src/gflags_reporting.cc.o
[ 37%] Building CXX object CMakeFiles/gflags_shared.dir/src/gflags.cc.o
[ 37%] Building CXX object CMakeFiles/gflags_shared.dir/src/gflags_reporting.cc.o
[ 50%] Building CXX object CMakeFiles/gflags_nothreads_shared.dir/src/gflags.cc.o
[ 62%] Building CXX object CMakeFiles/gflags_shared.dir/src/gflags_completions.cc.o
[ 75%] Building CXX object CMakeFiles/gflags_nothreads_shared.dir/src/gflags_completions.cc.o
[ 87%] Linking CXX shared library lib/libgflags_nothreads.so
[100%] Linking CXX shared library lib/libgflags.so
[100%] Built target gflags_nothreads_shared
[100%] Built target gflags_shared

这个其实已经有点开心了,因为看到了libgflags.so了,说明共享库成功生成了!
继续输入

sudo make install

看到的反馈信息如下:

➜  build git:(master) sudo make install
[ 50%] Built target gflags_nothreads_shared
[100%] Built target gflags_shared
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libgflags.so.2.2.1
-- Installing: /usr/local/lib/libgflags.so.2.2
-- Installing: /usr/local/lib/libgflags.so
-- Installing: /usr/local/lib/libgflags_nothreads.so.2.2.1
-- Installing: /usr/local/lib/libgflags_nothreads.so.2.2
-- Installing: /usr/local/lib/libgflags_nothreads.so
-- Installing: /usr/local/include/gflags/gflags.h
-- Installing: /usr/local/include/gflags/gflags_declare.h
-- Installing: /usr/local/include/gflags/gflags_completions.h
-- Installing: /usr/local/lib/cmake/gflags/gflags-config.cmake
-- Installing: /usr/local/lib/cmake/gflags/gflags-config-version.cmake
-- Old export file "/usr/local/lib/cmake/gflags/gflags-targets.cmake" will be replaced.  Removing files [/usr/local/lib/cmake/gflags/gflags-targets-release.cmake].
-- Installing: /usr/local/lib/cmake/gflags/gflags-targets.cmake
-- Installing: /usr/local/lib/cmake/gflags/gflags-targets-release.cmake
-- Up-to-date: /usr/local/bin/gflags_completions.sh
-- Installing: /usr/local/lib/pkgconfig/gflags.pc
-- Installing: /home/hri/.cmake/packages/gflags/e5f7ce61772240490d3164df06f58ce9

好了还有最后一步:

Step4:

输入:

sudo ldconfig

这个的意思就是加载动态链接库,一般是编译安装软件时候出现动态链接库报错需要手动加载下!
好了,再去执行程序,发现这个上面第一个报错没有了,但是又出现了第二个报错:
————————————————————————————————————————————

报错(2)


./curve_fitting: symbol lookup error: /usr/local/lib/libglog.so.0: undefined symbol: _ZN6google14FlagRegistererC1ISsEEPKcS3_S3_PT_S5_

这个时候发现,原来和上面那个gflag是一毛一样的错误!那就继续照猫画虎修改!

报错(2)解决办法

Step1:获取glog

git clone https://github.com/google/glog

Step2:编译glog

依次执行一下命令,(每行是一个单独命令!)

cd glog
./autogen.sh
sudo CFLAGS="-fPIC" ./configure
mkdri build
cd build
cmake -D BUILD_gflags_LIBS=ON  -D BUILD_SHARED_LIBS=ON -D BUILD_gflags_nothreads_LIBS=ON -D GFLAGS_NAMESPACE=ON ..
make -j4
sudo make install

——————————————————————————————————————————————————————
好的,完美解决了!也看到了libglog.so的共享库了!
然后再去执行十四讲第六章的程序,完美通过!

猜你喜欢

转载自blog.csdn.net/Amazingren/article/details/81873514