在Arch Linux中通过CMake安装XGBoost时遇依赖目录错误
问题场景
从Git仓库安装XGBoost时,执行以下编译命令:
cd xgboost mkdir build cd build cmake ..
运行cmake ..时触发如下错误:
-- CMake version 3.25.0
-- xgboost VERSION: 2.1.0
CMake Error at CMakeLists.txt:227 (add_subdirectory):
The source directory/mnt/32F6E6CAF6E68D83/Downloads/xgboost/dmlc-coredoes not contain a CMakeLists.txt file.
CMake Error at cmake/Utils.cmake:198 (set_target_properties):
set_target_properties Can not find target to add properties to: dmlc
Call Stack (most recent call first):
CMakeLists.txt:307 (xgboost_target_properties)CMake Error at cmake/Utils.cmake:270 (target_link_libraries):
Cannot specify link libraries for target "dmlc" which is not built by this
project.
Call Stack (most recent call first):
CMakeLists.txt:308 (xgboost_target_link_libraries)-- Configuring incomplete, errors occurred!
See also "/mnt/32F6E6CAF6E68D83/Downloads/xgboost/CMakeFiles/CMakeOutput.log".
问题原因
dmlc-core是XGBoost依赖的核心子模块,克隆仓库时未同步拉取子模块内容,导致该目录缺失必要的CMake配置文件,进而触发编译错误。
修复步骤
- 切换到xgboost主目录:
cd /mnt/32F6E6CAF6E68D83/Downloads/xgboost - 初始化并更新所有子模块:
git submodule init git submodule update - 清理旧的编译缓存并重新执行编译流程:
rm -rf build mkdir build cd build cmake ..
内容的提问来源于stack exchange,提问作者Vaibhav Singh Chandel

