👏
M1 Macでceres-solver(v2.2.0)のビルド
brewで以下をインストール。
brew install cmake
brew install ceres-solver # 2024/2のHEADはv2.2.0。Eigen等もインストールされる
CmakeLists.txtを作成します。
cmake_minimum_required(VERSION 3.6)
project(a.out VERSION 0.0.1)
add_executable(${PROJECT_NAME} helloworld.cc)
# 参考 https://qiita.com/mitsuruk9999/items/b8a4094f558a9c36e208
set(BREW_DIR "/opt/homebrew")
target_include_directories(${PROJECT_NAME} PRIVATE ${BREW_DIR}/include)
target_link_directories(${PROJECT_NAME} PRIVATE ${BREW_DIR}/lib)
find_package(Ceres REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${CERES_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CERES_INCLUDE_DIRS})
target_compile_features(${PROJECT_NAME} PRIVATE c_std_17 cxx_std_17)
target_compile_options(${PROJECT_NAME} PRIVATE -O2 -Wall )
v2.2.0のexample/helloworld.ccをビルドして実行します。[1]
cmake .
make
./a.out
出力が以下のようになれば成功です。
iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time
0 4.512500e+01 0.00e+00 9.50e+00 0.00e+00 0.00e+00 1.00e+04 0 4.99e-04 8.29e-03
1 4.511598e-07 4.51e+01 9.50e-04 0.00e+00 1.00e+00 3.00e+04 1 1.88e-03 1.03e-02
2 5.012552e-16 4.51e-07 3.17e-08 9.50e-04 1.00e+00 9.00e+04 1 3.10e-06 1.03e-02
Ceres Solver Report: Iterations: 3, Initial cost: 4.512500e+01, Final cost: 5.012552e-16, Termination: CONVERGENCE
x : 0.5 -> 10
参考
-
最新のexample/helloworld.ccだとAutoDiffCostFunctionの引数が無いので注意 https://ceres-solver.googlesource.com/ceres-solver/+/91773746be74a58029f6ecfc0c82a3b22492ed12^!/examples/helloworld.cc ↩︎
Discussion