今天在编译程序的时候,遇到了关于glog库和问题
首先我编译了ceres库
ceres:http://ceres-solver.org/installation.html#linux
ceres在安装前安装了glog作为依赖,如下:
# CMake
sudo apt-get install cmake
# google-glog + gflags
sudo apt-get install libgoogle-glog-dev libgflags-dev
# BLAS & LAPACK
sudo apt-get install libatlas-base-dev
# Eigen3
sudo apt-get install libeigen3-dev
# SuiteSparse and CXSparse (optional)
sudo apt-get install libsuitesparse-dev
cmake安装ceres的make -j8记录显示:
$ cmake -D CMAKE_INSTALL_PREFIX=../install ..
.....只看glog的这一段
No preference for use of exported glog CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported glog CMake configuration if available.
-- Failed to find installed glog CMake configuration, searching for glog build directories exported with CMake.
-- Failed to find an installed/exported CMake configuration for glog, will perform search for installed glog components.
-- Found Glog: /usr/include
-- Found Google Log (glog). Assuming glog was built with gflags support as gflags was found. This will make gflags a public dependency of Ceres.
.....
说明apt install libgoogle-glog-dev是直接安进了系统目录,和自己编译库的方式是不一样的。
两种安库的方式
1、apt install dev是直接安进了系统目录
2、自己编译库 生成了:*.lib / *.so / *.cmake等文件,需要sudo make install按到系统路径下(当然也可以不安到系统路径里)
所以,在其他程序调用库的时候,cmakelists.txt就不太一样了:
cmakelists.txt 调用ceres
set(Ceres_DIR "~/pkg/test/install/lib/cmake/Ceres")
find_package(Ceres REQUIRED)
因为是自己编译的库,没有问题
但是
cmakelists.txt 调用glog
# include_directories(/usr/include) # 加不加都没用
find_package(Glog)
因为不是自己编译的库,就找不到了
报错:
-- looking for PCL_REGISTRATION
-- looking for PCL_KEYPOINTS
-- looking for PCL_TRACKING
-- looking for PCL_RECOGNITION
-- looking for PCL_STEREO
-- looking for PCL_APPS
-- looking for PCL_IN_HAND_SCANNER
-- looking for PCL_MODELER
-- looking for PCL_POINT_CLOUD_EDITOR
-- looking for PCL_OUTOFCORE
-- looking for PCL_PEOPLE
CMake Error at A-LOAM/CMakeLists.txt:25 (find_package):
By not providing "FindCeres.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Ceres", but
CMake did not find one.
Could not find a package configuration file provided by "Ceres" with any of
the following names:
CeresConfig.cmake
ceres-config.cmake
Add the installation prefix of "Ceres" to CMAKE_PREFIX_PATH or set
"Ceres_DIR" to a directory containing one of the above files. If "Ceres"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
不是自己编译的,当然找不到*.cmake
所以,这里要用glog库的时候直接调用就行了,写了反而出错了。
cmakelists.txt
add_executable( curvefitting curvefitting.cpp )
target_link_libraries(curvefitting ceres)
c++:
#include "ceres/ceres.h" #include "glog/logging.h"
没有问题的
cmakelists.txt
add_executable( curvefitting curvefitting.cpp )
target_link_libraries(curvefitting ceres glog)
也没有问题
备注:
这里不知道是不是因为ceres编译的时候用了glog,所以调用ceres和glog,不需要写glog;
如果只用glog,不知道会不会有问题
以后再试吧