IT 스터디/Ubuntu

Ubuntu 18.04 에서 Ceres Solver 설치하기 (Compile Error 발생 및 해결)

KimDol2 2023. 6. 30. 10:22

 

 

LiDAR SLAM 알고리즘을 돌려볼 때 많은 알고리즘들이 최적화 라이브러리로 Ceres Solver 를 사용한다. 우분투 데스크탑 장비에 Ceres Solver를 설치하다 발생한 문제가 있었는데 한참 삽질 끝에 해결했다. 먼저 Ceres Solver의 설치는 아래 링크를 따라하면 된다.

 

 

 

Installation — Ceres Solver

When building Ceres, some dependencies (Eigen, gflags) are not found using custom Find .cmake modules any more. Hence, instead of the custom variables ( _INCLUDE_DIR_HINTS , _INCLUDE_DIR , …) you should use standard CMake facilities to customize where th

ceres-solver.org

 

그런데 cmake로 빌드 환경을 만들고 make -j3 을 실행하게 되면 아래와 같이 ceres solver의 종속성이 있는 google-glog 라이브러리 인클루드에서 에러가 발생한다. 

/usr/include/glog/logging.h:638:9: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘std::nullptr_t’)
   (*os) << v;
   ~~~~~~^~~~
In file included from /usr/include/glog/logging.h:43,
                 from /home/jupyter/ceres-solver/internal/ceres/concurrent_queue.h:39,
                 from /home/jupyter/ceres-solver/internal/ceres/thread_pool.h:39,
                 from /home/jupyter/ceres-solver/internal/ceres/context_impl.h:52,
                 from /home/jupyter/ceres-solver/internal/ceres/cuda_vector.cc:40:

 

위의 문제는 ceres github 에도 issue로 등록되어 있는 문제인데 등록된 해결 방법은 없는 듯 하다.

 

Building Ceres Fails. · Issue #931 · ceres-solver/ceres-solver

I've been trying to build Ceres on a VM using the instructions provided here. Everything till the cmake steps seems to be working correctly. However, when I perform make -j3 I get the following err...

github.com

 

에러 문제의 원인은 CUDA 가 설치되어 있으면 cmake 로 빌드 환경을 만들 때 아래와 같이 CUDA 를 찾게 되고 CUDA 를 사용하여 빌드 환경을 구축하게 된다. (아래 cmake 빌드 로그의 4번째 라인을 보면  CUDA를 찾고 CUDA를 사용하여 빌드하게끔 셋팅이 된다.)

cmake ../ceres-solver-2.1.0
-- Detected Ceres version: 2.2.0 from /home/kbk/ceres/ceres-solver/include/ceres/version.h
-- Found Eigen version 3.3.4: /usr/lib/cmake/eigen3
-- Enabling use of Eigen as a sparse linear algebra library.
-- Found CUDA version 10.2.300 installed in: /usr/local/cuda
-- Setting CUDA Architecture to 50;60;70;80
-- Found LAPACK library: /usr/lib/x86_64-linux-gnu/liblapack.so;/usr/lib/x86_64-linux-gnu/libblas.so;/usr/lib/x86_64-linux-gnu/libf77blas.so;/usr/lib/x86_64-linux-gnu/libatlas.so
-- Found CHOLMOD headers in: /usr/include/suitesparse
-- Found CHOLMOD library: /usr/lib/x86_64-linux-gnu/libcholmod.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 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 COLAMD headers in: /usr/include/suitesparse
-- Found COLAMD library: /usr/lib/x86_64-linux-gnu/libcolamd.so
-- Found Intel Thread Building Blocks (TBB) library (2017.0 / 9107) include location: /usr/include. Assuming SuiteSparseQR was compiled with TBB.
-- Adding librt to SuiteSparse_config libraries (required on Linux & Unix [not OSX] if SuiteSparse is compiled with timing).
-- Could NOT find METIS (missing: METIS_INCLUDE_DIR METIS_LIBRARY) 
-- Found SuiteSparse 5.1.2, building with SuiteSparse.
-- Building without Eigen METIS support.
-- Building without Apple's Accelerate sparse support.
-- Found Google Flags (gflags) version 2.2.1: /usr/lib/x86_64-linux-gnu/cmake/gflags
-- 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 Google Log (glog). Assuming glog was built with gflags support as gflags was found. This will make gflags a public dependency of Ceres.
-- Building Ceres as a static library.
-- Enabling CERES_USE_EIGEN_SPARSE in Ceres config.h
-- Enabling CERES_NO_ACCELERATE_SPARSE in Ceres config.h
-- Enabling CERES_NO_CHOLMOD_PARTITION in Ceres config.h
-- Enabling CERES_NO_EIGEN_METIS in Ceres config.h
-- Build the examples.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kbk/ceres/ceres-bin

 

따라서 CMakeLists.txt 파일에서 CUDA를 사용하지 않도록 변경해 준다.

option(USE_CUDA "Enable use of CUDA linear algebra solvers." OFF) # ON 에서 OFF로 변경

 

변경 후 cmake를 다시하게되면 아래와 같이 'CUDA를 사용하지 않고 빌드' 옵션이 적용된다. (4번째 라인의 Building without CUDA.)

-- Detected Ceres version: 2.2.0 from /home/kbk/ceres/ceres-solver/include/ceres/version.h
-- Found Eigen version 3.3.4: /usr/lib/cmake/eigen3
-- Enabling use of Eigen as a sparse linear algebra library.
-- Building without CUDA.
-- Found LAPACK library: /usr/lib/x86_64-linux-gnu/liblapack.so;/usr/lib/x86_64-linux-gnu/libblas.so;/usr/lib/x86_64-linux-gnu/libf77blas.so;/usr/lib/x86_64-linux-gnu/libatlas.so
-- Found CHOLMOD headers in: /usr/include/suitesparse
-- Found CHOLMOD library: /usr/lib/x86_64-linux-gnu/libcholmod.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 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 COLAMD headers in: /usr/include/suitesparse
-- Found COLAMD library: /usr/lib/x86_64-linux-gnu/libcolamd.so
-- Found Intel Thread Building Blocks (TBB) library (2017.0 / 9107) include location: /usr/include. Assuming SuiteSparseQR was compiled with TBB.
-- Adding librt to SuiteSparse_config libraries (required on Linux & Unix [not OSX] if SuiteSparse is compiled with timing).
-- Could NOT find METIS (missing: METIS_INCLUDE_DIR METIS_LIBRARY) 
-- Found SuiteSparse 5.1.2, building with SuiteSparse.
-- Building without Eigen METIS support.
-- Building without Apple's Accelerate sparse support.
-- Found Google Flags (gflags) version 2.2.1: /usr/lib/x86_64-linux-gnu/cmake/gflags
-- 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 Google Log (glog). Assuming glog was built with gflags support as gflags was found. This will make gflags a public dependency of Ceres.
-- Building Ceres as a static library.
-- Enabling CERES_USE_EIGEN_SPARSE in Ceres config.h
-- Enabling CERES_NO_CUDA in Ceres config.h
-- Enabling CERES_NO_ACCELERATE_SPARSE in Ceres config.h
-- Enabling CERES_NO_CHOLMOD_PARTITION in Ceres config.h
-- Enabling CERES_NO_EIGEN_METIS in Ceres config.h
-- Build the examples.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kbk/ceres/ceres-bin

 

이렇게 빌드 환경을 만든 후 다시 make -j3 을 실행하면 위의 에러 없이 Ceres Solver가 컴파일 된다. 아마도  CUDA를 적용하면 CUDA 컴파일러로 코드가 컴파일 되는데, 위와 같이 (*os) << v 와 같은 코드에서 발생되는 ambiguity 를 처리하지 못해서 발생되는 에러인 것 같다. 

 

 

반응형