执行cmake .. -GNinja时COLMAP安装报错的解决求助
COLMAP源码编译CMake报错:glog::glog目标重复
问题描述
按照COLMAP官方源码构建指南从源码安装时,执行cmake .. -GNinja步骤遇到如下错误,手动安装Ceres后问题依旧,求解决方法。
错误日志
-- The C compiler identification is GNU 9.4.0 -- The CXX compiler identification is GNU 9.4.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") found components: filesystem graph program_options system -- Found FreeImage -- Includes : /usr/include -- Libraries : /usr/lib/x86_64-linux-gnu/libfreeimage.so -- Found FLANN -- Includes : /usr/include -- Libraries : /usr/lib/x86_64-linux-gnu/libflann.so -- Found LZ4 -- Includes : /usr/include -- Libraries : /usr/lib/x86_64-linux-gnu/liblz4.so -- Found Metis -- Includes : /usr/include -- Libraries : /usr/lib/x86_64-linux-gnu/libmetis.so -- Found Glog -- Includes : /usr/include -- Libraries : /usr/lib/x86_64-linux-gnu/libglog.so -- Found SQLite3: /usr/include (found version "3.31.1") -- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so -- Found Glew -- Includes : /usr/include -- Libraries : /usr/lib/x86_64-linux-gnu/libGLEW.so -- Found Git: /usr/bin/git (found version "2.25.1") -- Found METIS: /usr/include (found suitable version "5.1.0", minimum required is "5.1.0") -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Found AMD headers in: /usr/include/suitesparse -- Found AMD library: /usr/lib/x86_64-linux-gnu/libamd.so -- Found CAMD headers in: /usr/include/suitesparse -- Found CAMD library: /usr/lib/x86_64-linux-gnu/libcamd.so -- Found CCOLAMD headers in: /usr/include/suitesparse -- Found CCOLAMD library: /usr/lib/x86_64-linux-gnu/libccolamd.so -- Found CHOLMOD headers in: /usr/include/suitesparse -- Found CHOLMOD library: /usr/lib/x86_64-linux-gnu/libcholmod.so -- Found COLAMD headers in: /usr/include/suitesparse -- Found COLAMD library: /usr/lib/x86_64-linux-gnu/libcolamd.so -- Found SPQR headers in: /usr/include/suitesparse -- Found SPQR library: /usr/lib/x86_64-linux-gnu/libspqr.so -- Found Config headers in: /usr/include/suitesparse -- Found Config library: /usr/lib/x86_64-linux-gnu/libsuitesparseconfig.so -- Found Intel Thread Building Blocks (TBB) library (2020.1 / 11101). Assuming SuiteSparseQR was compiled with TBB. -- Looking for shm_open in rt -- Looking for shm_open in rt - found -- Adding librt to SuiteSparse_config libraries (required on Linux & Unix [not OSX] if SuiteSparse is compiled with timing). -- Found METIS: /usr/include (found version "5.1.0") -- Looking for cholmod_metis -- Looking for cholmod_metis - found -- Found SuiteSparse: /usr/include/suitesparse (found suitable version "5.7.1", minimum required is "5.7.1") found components: AMD CAMD CCOLAMD CHOLMOD COLAMD SPQR Config -- Found CUDAToolkit: /usr/local/cuda/include (found suitable version "11.4.152", minimum required is "11.4.152") -- Found required Ceres dependency: Eigen version 3.4.0 in /usr/share/eigen3/cmake CMake Error at /usr/local/lib/cmake/Ceres/FindGlog.cmake:349 (add_library): add_library cannot create imported target "glog::glog" because another target with the same name already exists. Call Stack (most recent call first): /usr/local/lib/cmake/Ceres/CeresConfig.cmake:247 (find_package) cmake/FindDependencies.cmake:38 (find_package) CMakeLists.txt:85 (include) -- Found required Ceres dependency: glog -- Found required Ceres dependency: gflags -- Found Ceres version: 2.2.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, SchurSpecializations] -- Enabling OpenMP support -- Using header-only CGAL -- Targetting Ninja -- Using /usr/bin/c++ compiler. -- Found GMP: /usr/lib/x86_64-linux-gnu/libgmp.so -- Found MPFR: /usr/lib/x86_64-linux-gnu/libmpfr.so -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.48") -- Boost include dirs: /usr/include -- Boost libraries: -- Using gcc version 4 or later. Adding -frounding-math -- Found CGAL -- Includes : /usr/include -- Libraries : CGAL -- The CUDA compiler identification is NVIDIA 11.4.152 -- Detecting CUDA compiler ABI info -- Detecting CUDA compiler ABI info - done -- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc - skipped -- Detecting CUDA compile features -- Detecting CUDA compile features - done -- Enabling CUDA support (version: 11.4.152, archs: native) -- Found Qt -- Module : /home/user/anaconda3/lib/cmake/Qt5Core -- Module : /home/user/anaconda3/lib/cmake/Qt5OpenGL -- Module : /home/user/anaconda3/lib/cmake/Qt5Widgets -- Enabling GUI support -- Enabling OpenGL support -- Enabling GPU support -- Build type not specified, using Release -- Enabling SIMD support -- Disabling interprocedural optimization -- Disabling ccache support -- Disabling profiling support -- Configuring incomplete, errors occurred! See also "/home/user/colmap/build/CMakeFiles/CMakeOutput.log". See also "/home/user/colmap/build/CMakeFiles/CMakeError.log".
解决方法
方法1:指定CMake跳过重复查找glog
执行cmake时添加参数,让COLMAP直接使用系统已找到的glog,避免Ceres的查找脚本重复创建目标:
cmake .. -GNinja -DCMAKE_DISABLE_FIND_PACKAGE_Glog=ON
方法2:重新编译Ceres并绑定系统glog
如果是手动编译的Ceres,重新编译时指定系统glog的路径,让Ceres直接链接已有的库:
# 进入Ceres源码目录 mkdir -p build && cd build cmake .. -DGLOG_INCLUDE_DIR=/usr/include -DGLOG_LIBRARY=/usr/lib/x86_64-linux-gnu/libglog.so make -j$(nproc) sudo make install
完成后重新执行COLMAP的cmake配置。
方法3:清理冲突的glog版本
如果系统中存在多个glog安装(比如系统包+手动编译版本),卸载手动安装的版本,保留系统默认包:
sudo apt remove libgoogle-glog-dev sudo apt install --reinstall libgoogle-glog-dev
之后重新运行COLMAP的cmake命令。
内容的提问来源于stack exchange,提问作者SJ Moon
相关产品推荐
相关产品推荐

