CMake Error:add_library cannot create imported target “glog::glog“

文章讲述了在CMake的FindGlog模块中,由于目标glog::glog已存在,导致添加错误。提供了解决方案:在添加glog::glogtarget之前检查其是否存在,若不存在则进行添加。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

 SOLUTION:在add glog::glog target之前判断一下是否target到glog::glog了,如果没有target到,再添加glog::glog target。在/usr/local/lib/cmake/Ceres下的FindGlog.cmake文件中的

# add glog::glog target
add_library(glog::glog INTERFACE IMPORTED)
target_include_directories(glog::glog INTERFACE ${GLOG_INCLUDE_DIRS})
target_link_libraries(glog::glog INTERFACE ${GLOG_LIBRARY})

修改为:

# add glog::glog target
if(NOT TARGET glog::glog)
    add_library(glog::glog INTERFACE IMPORTED)
    target_include_directories(glog::glog INTERFACE ${GLOG_INCLUDE_DIRS})
    target_link_libraries(glog::glog INTERFACE ${GLOG_LIBRARY})
endif()

kaleojyt@JYT:~/calibration/catkin_ws$ catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3 Base path: /home/kaleojyt/calibration/catkin_ws Source space: /home/kaleojyt/calibration/catkin_ws/src Build space: /home/kaleojyt/calibration/catkin_ws/build Devel space: /home/kaleojyt/calibration/catkin_ws/devel Install space: /home/kaleojyt/calibration/catkin_ws/install Creating symlink "/home/kaleojyt/calibration/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/noetic/share/catkin/cmake/toplevel.cmake" #### #### Running command: "cmake /home/kaleojyt/calibration/catkin_ws/src -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCATKIN_DEVEL_PREFIX=/home/kaleojyt/calibration/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/kaleojyt/calibration/catkin_ws/install -G Unix Makefiles" in "/home/kaleojyt/calibration/catkin_ws/build" #### -- The C compiler identification is GNU 9.4.0 -- The CXX compiler identification is GNU 9.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using CATKIN_DEVEL_PREFIX: /home/kaleojyt/calibration/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Found PY_em: /usr/lib/python3/dist-packages/em.py -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/kaleojyt/calibration/catkin_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Found Threads: TRUE -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 1 packages in topological order: -- ~~ - code_utils -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'code_utils' -- ==> add_subdirectory(code_utils) -- Found OpenCV: /usr (found version "4.2.0") -- Found BLAS: /usr/lib/x86_64-linux-gnu/libf77blas.so;/usr/lib/x86_64-linux-gnu/libatlas.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 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) include location: . 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). -- Could NOT find METIS (missing: METIS_INCLUDE_DIR METIS_LIBRARY) -- 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 required Ceres dependency: Eigen version 3.3.7 in /usr/lib/cmake/eigen3 -- 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] -- Configuring done CMake Warning (dev) at code_utils/CMakeLists.txt:35 (add_library): Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "pnp" links to target "CUDA::cublas" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) at code_utils/CMakeLists.txt:35 (add_library): Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "pnp" links to target "CUDA::cudart" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) at code_utils/CMakeLists.txt:35 (add_library): Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "pnp" links to target "CUDA::cusolver" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) at code_utils/CMakeLists.txt:35 (add_library): Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "pnp" links to target "CUDA::cusparse" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it. -- Generating done -- Build files have been written to: /home/kaleojyt/calibration/catkin_ws/build #### #### Running command: "make -j32 -l32" in "/home/kaleojyt/calibration/catkin_ws/build" #### Scanning dependencies of target matIO_test Scanning dependencies of target sumpixel_test Scanning dependencies of target pnp Scanning dependencies of target polynomial Scanning dependencies of target cv_utils [ 7%] Building CXX object code_utils/CMakeFiles/polynomial.dir/src/math_utils/Polynomial.cpp.o [ 15%] Building CXX object code_utils/CMakeFiles/sumpixel_test.dir/src/sumpixel_test.cpp.o [ 23%] Building CXX object code_utils/CMakeFiles/matIO_test.dir/src/mat_io_test.cpp.o [ 30%] Building CXX object code_utils/CMakeFiles/pnp.dir/src/cv_utils/dlt/dlt.cpp.o [ 38%] Building CXX object code_utils/CMakeFiles/cv_utils.dir/src/cv_utils.cc.o [ 46%] Building CXX object code_utils/CMakeFiles/pnp.dir/src/cv_utils/pnp/pnp.cpp.o [ 53%] Building CXX object code_utils/CMakeFiles/pnp.dir/src/cv_utils/pnp/nonlinearpnp.cpp.o [ 61%] Building CXX object code_utils/CMakeFiles/pnp.dir/src/cv_utils/pnp/linearpnp.cpp.o [ 69%] Linking CXX static library /home/kaleojyt/calibration/catkin_ws/devel/lib/libcv_utils.a [ 69%] Built target cv_utils [ 76%] Linking CXX executable /home/kaleojyt/calibration/catkin_ws/devel/lib/code_utils/sumpixel_test [ 84%] Linking CXX executable /home/kaleojyt/calibration/catkin_ws/devel/lib/code_utils/matIO_test [ 84%] Built target sumpixel_test [ 84%] Built target matIO_test /home/kaleojyt/calibration/catkin_ws/src/code_utils/src/math_utils/Polynomial.cpp: In member function ‘double math_utils::Polynomial::getOneRealRoot(double, double, double)’: /home/kaleojyt/calibration/catkin_ws/src/code_utils/src/math_utils/Polynomial.cpp:64:25: warning: control reaches end of non-void function [-Wreturn-type] 64 | eigen_utils::Vector realRoots, imagRoots; | ^~~~~~~~~ [ 92%] Linking CXX static library /home/kaleojyt/calibration/catkin_ws/devel/lib/libpolynomial.a [ 92%] Built target polynomial [100%] Linking CXX shared library /home/kaleojyt/calibration/catkin_ws/devel/lib/libpnp.so /usr/bin/ld: 找不到 -lCUDA::cusolver /usr/bin/ld: 找不到 -lCUDA::cusparse collect2: error: ld returned 1 exit status make[2]: *** [code_utils/CMakeFiles/pnp.dir/build.make:192:/home/kaleojyt/calibration/catkin_ws/devel/lib/libpnp.so] 错误 1 make[1]: *** [CMakeFiles/Makefile2:804:code_utils/CMakeFiles/pnp.dir/all] 错误 2 make: *** [Makefile:141:all] 错误 2 Invoking "make -j32 -l32" failed
最新发布
07-12
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值