编译ORB-SLAM3时CMake无法识别epoxy库的问题求助
解决ORB-SLAM3编译时epoxy库链接失败问题
问题现象
编译ORB-SLAM3时出现链接错误:
[ 39%] Linking CXX shared library ../lib/libORB_SLAM3.so /usr/bin/ld: cannot find -lepoxy::epoxy: No such file or directory collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/ORB_SLAM3.dir/build.make:605: ../lib/libORB_SLAM3.so] Error 1 make[1]: *** [CMakeFiles/Makefile2:192: CMakeFiles/ORB_SLAM3.dir/all] Error 2 make: *** [Makefile:91: all] Error 2
已通过sudo apt-get install libepoxy-dev安装epoxy库,但CMake仍无法识别;添加find_package(epoxy REQUIRED)后编译报错:
CMake Error at CMakeLists.txt:46 (find_package): By not providing "Findepoxy.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "epoxy", but CMake did not find one. Could not find a package configuration file provided by "epoxy" with any of the following names: epoxyConfig.cmake epoxy-config.cmake Add the installation prefix of "epoxy" to CMAKE_PREFIX_PATH or set "epoxy_DIR" to a directory containing one of the above files. If "epoxy" provides a separate development package or SDK, be sure it has been installed.
同时伴随CMake警告:
CMake Warning (dev) at CMakeLists.txt:391 (add_executable): 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 "stereo_inertial_realsense_D435i_old" links to target "epoxy::epoxy" 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.
解决方案
方法1:手动创建epoxy的CMake导入目标
系统包安装的epoxy缺少CMake配置文件,可手动在ORB-SLAM3的CMakeLists.txt中添加导入规则:
- 确认epoxy的安装路径:头文件通常在
/usr/include/epoxy/,库文件在/usr/lib/x86_64-linux-gnu/libepoxy.so(64位系统)或/usr/lib/i386-linux-gnu/libepoxy.so(32位系统)。 - 在CMakeLists.txt开头附近插入以下代码:
# 手动查找epoxy库和头文件 find_path(EPOXY_INCLUDE_DIR NAMES epoxy/gl.h) find_library(EPOXY_LIBRARY NAMES epoxy) # 创建epoxy::epoxy导入目标 add_library(epoxy::epoxy SHARED IMPORTED) set_target_properties(epoxy::epoxy PROPERTIES IMPORTED_LOCATION "${EPOXY_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${EPOXY_INCLUDE_DIR}" )
- 注释掉之前添加的
find_package(epoxy REQUIRED),重新执行cmake ..和make -j$(nproc)。
方法2:替换链接目标为原始库名
修改ORB-SLAM3 CMakeLists.txt中所有链接epoxy::epoxy的代码,将其替换为epoxy:
例如把target_link_libraries(stereo_inertial_realsense_D435i_old epoxy::epoxy ...)改为target_link_libraries(stereo_inertial_realsense_D435i_old epoxy ...),修改后重新编译。
方法3:从源码编译安装epoxy
源码编译的epoxy会生成完整的CMake配置文件,步骤如下:
# 克隆源码 git clone https://github.com/anholt/libepoxy.git cd libepoxy # 编译安装 mkdir build && cd build cmake .. make -j$(nproc) sudo make install
完成后重新编译ORB-SLAM3,find_package(epoxy REQUIRED)即可正常识别库。
内容的提问来源于stack exchange,提问作者Ilia Nechaev
相关产品推荐
相关产品推荐

