Windows下编译R包时RBuildTools报boost_program_options_FOUND错误的解决方法
解决R包编译时Boost Program Options未找到的问题
编译R包的C++代码时,执行Rcmd.exe INSTALL命令遇到boost_program_options_FOUND错误,已在CMakeLists.txt中添加set(Boost_USE_STATIC_LIBS ON)但问题仍存在,错误日志如下:
make[1]: Leaving directory '/d/OneDrive/Documents/flashlighttext/src/build' CMake Error at C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/cmake/Boost-1.81.0/BoostConfig.cmake:141 (find_package): Found package configuration file: C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/cmake/boost_program_options-1.81.0/boost_program_options-config.cmake but it set boost_program_options_FOUND to FALSE so package "boost_program_options" is considered to be NOT FOUND. Reason given by package: No suitable build variant has been found. The following variants have been tried and rejected: * libboost_program_options-mt-x64.a (static, Boost_USE_STATIC_LIBS=OFF)
修复方案
- 调整CMake设置顺序:确保
set(Boost_USE_STATIC_LIBS ON)放在find_package(Boost ...)命令之前,CMake按执行顺序读取配置,后置的设置不会影响之前的find_package操作。 - 明确指定Boost组件与多线程选项:修改CMakeLists.txt中的Boost查找逻辑,同时开启多线程静态库支持:
set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) find_package(Boost REQUIRED COMPONENTS program_options) - 清理旧缓存文件:删除编译生成的
build目录(即错误中提到的/d/OneDrive/Documents/flashlighttext/src/build),重新执行编译命令,避免旧配置缓存干扰。 - 手动指定Boost根目录:如果CMake仍未正确识别Boost路径,手动指定Boost安装根目录,确保配置生效:
set(BOOST_ROOT "C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix") set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) find_package(Boost REQUIRED COMPONENTS program_options) - 排查配置覆盖问题:检查项目中其他CMake脚本或R包编译的默认配置,是否有代码覆盖了
Boost_USE_STATIC_LIBS的设置,确保你的配置为最终生效项。
内容的提问来源于stack exchange,提问作者Athos
相关产品推荐
相关产品推荐

