-
Notifications
You must be signed in to change notification settings - Fork 171
Description
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)
build/_deps/colmap-src/cmake/FindDependencies.cmake:50 (find_package)
build/_deps/colmap-src/CMakeLists.txt:112 (include)
CMake Error at /usr/local/lib/cmake/Ceres/FindGlog.cmake:351 (target_link_libraries):
Cannot specify link libraries for target "glog::glog" which is not built by
this project.
Call Stack (most recent call first):
/usr/local/lib/cmake/Ceres/CeresConfig.cmake:247 (find_package)
build/_deps/colmap-src/cmake/FindDependencies.cmake:50 (find_package)
build/_deps/colmap-src/CMakeLists.txt:112 (include)
Problem: CMake error because glog::glog was created twice — once by the project's FindGlog.cmake and again by Ceres's FindGlog.cmake when COLMAP configured.
Solution: Two changes:
cmake/FindGlog.cmake (line 111): Added a guard before creating the target:
if(NOT TARGET glog::glog)
add_library(glog::glog INTERFACE IMPORTED)
...
endif()
Prevents recreating the target if it already exists.
cmake/FindDependencies.cmake (lines 9-16): Find glog before Ceres:
Find glog before Ceres to avoid conflicts
if(NOT TARGET glog::glog)
find_package(Glog QUIET)
if(TARGET glog::glog)
set(GLOG_FOUND TRUE CACHE BOOL "Glog library found" FORCE)
endif()
endif()
find_package(Ceres REQUIRED COMPONENTS SuiteSparse)
Ensures glog::glog exists before Ceres's FindGlog runs, so Ceres won't try to create it again.
Result: The target is created once, and subsequent attempts to create it are skipped, resolving the conflict.