LightGBM: [R-package] [gpu] Unable to properly pass boost directories to Rbuild on Windows 10

Description

I am trying to build LightGBM for R on Windows 10 with GPU support. I have the Boost libraries for MS VS 2022 installed under C:\local\boost_1_78_0 as recommended, but Rtools42 comes with its own version of Boost which the Cmake finds first. When I pass --msys2, the build works properly. However, when I do not pass it, It fails with a multitude of errors such as:

C:\rtools42\x86_64-w64-mingw32.static.posix\include\math.h(220,35): error C2143: syntax error: missing ')' before ':' (compiling source file D:\Rtemp\RtmpQXP90R\Rbuild1aa440765be\lightgbm\src\src\boosting\gbdt_prediction.cpp) [D:\Rtemp\RtmpQXP90R\Rbuild1aa440765be\lightgbm\src\build\lightgbm_objs.vcxproj]

I believe this is due to the build expecting VS as the compiler but finding the wrong boost libraries as per

-- Found Boost: C:/rtools42/x86_64-w64-mingw32.static.posix/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.56.0") found components: filesystem system

Reproducible example

I have tried various invocations to pass the proper locations and all fail

D:\LightGBM>Rscript build_r.R --use-gpu --boost-root="C:\local\boost_1_78_0"
* checking for file 'D:/LightGBM/lightgbm_r/DESCRIPTION' ... OK
* preparing 'lightgbm':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to build vignettes
      -----------------------------------
* installing *source* package 'lightgbm' ...
** using staged installation
** libs
installing via 'install.libs.R' to D:/Rtemp/Rtmpc30IfG/Rinst23247b9c6d46/00LOCK-lightgbm/00new/lightgbm
Error in source("install.libs.R", local = local.env) :
  install.libs.R:142:39: unexpected symbol
141: # NOTE: build_r.R replaces the line below
142: command_line_args <- c("-DBOOST_ROOT="C
                                           ^
* removing 'D:/Rtemp/Rtmpc30IfG/Rinst23247b9c6d46/lightgbm'
      -----------------------------------
ERROR: package installation failed
Error in .run_shell_command("R", r_build_args) :
  Command failed with exit code: 1
Execution halted

D:\LightGBM>Rscript build_r.R --use-gpu --boost-root=/c/local/boost_1_78_0
* checking for file 'D:/LightGBM/lightgbm_r/DESCRIPTION' ... OK
* preparing 'lightgbm':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to build vignettes
      -----------------------------------
* installing *source* package 'lightgbm' ...
** using staged installation
** libs
installing via 'install.libs.R' to D:/Rtemp/RtmpOmpkRY/Rinst35ec7ab6d15/00LOCK-lightgbm/00new/lightgbm
Error in source("install.libs.R", local = local.env) :
  install.libs.R:142:60: unexpected string constant
141: # NOTE: build_r.R replaces the line below
142: command_line_args <- c("-DBOOST_ROOT="/c/local/boost_1_78_0""
                                                                ^
* removing 'D:/Rtemp/RtmpOmpkRY/Rinst35ec7ab6d15/lightgbm'
      -----------------------------------
ERROR: package installation failed
Error in .run_shell_command("R", r_build_args) :
  Command failed with exit code: 1
Execution halted

D:\LightGBM>Rscript build_r.R --use-gpu --boost-root=C:\local\boost_1_78_0
* checking for file 'D:/LightGBM/lightgbm_r/DESCRIPTION' ... OK
* preparing 'lightgbm':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to build vignettes
      -----------------------------------
* installing *source* package 'lightgbm' ...
** using staged installation
** libs
installing via 'install.libs.R' to D:/Rtemp/RtmpaK6A5z/Rinst4d40273f38da/00LOCK-lightgbm/00new/lightgbm
Error in source("install.libs.R", local = local.env) :
  install.libs.R:142:39: unexpected symbol
141: # NOTE: build_r.R replaces the line below
142: command_line_args <- c("-DBOOST_ROOT="C
                                           ^
* removing 'D:/Rtemp/RtmpaK6A5z/Rinst4d40273f38da/lightgbm'
      -----------------------------------
ERROR: package installation failed
Error in .run_shell_command("R", r_build_args) :
  Command failed with exit code: 1
Execution halted

D:\LightGBM>Rscript build_r.R --use-gpu --boost-librarydir=C:\local\boost_1_78_0\lib64-msvc-14.3 --boost-root=/c/local/boost_1_78_0/
* checking for file 'D:/LightGBM/lightgbm_r/DESCRIPTION' ... OK
* preparing 'lightgbm':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to build vignettes
      -----------------------------------
* installing *source* package 'lightgbm' ...
** using staged installation
** libs
installing via 'install.libs.R' to D:/Rtemp/Rtmp61NNAI/Rinst269445816411/00LOCK-lightgbm/00new/lightgbm
Error in source("install.libs.R", local = local.env) :
  install.libs.R:142:45: unexpected symbol
141: # NOTE: build_r.R replaces the line below
142: command_line_args <- c("-DBOOST_LIBRARYDIR="C
                                                 ^
* removing 'D:/Rtemp/Rtmp61NNAI/Rinst269445816411/lightgbm'
      -----------------------------------
ERROR: package installation failed
Error in .run_shell_command("R", r_build_args) :
  Command failed with exit code: 1
Execution halted

D:\LightGBM>Rscript build_r.R --use-gpu --boost-librarydir=C\local\boost_1_78_0\lib64-msvc-14.3 --boost-root=c/local/boo
st_1_78_0/
D:\LightGBM>Rscript build_r.R --use-gpu --boost-librarydir=C\local\boost_1_78_0\lib64-msvc-14.3 --boost-root=c\local\boost_1_78_0
* checking for file 'D:/LightGBM/lightgbm_r/DESCRIPTION' ... OK
* preparing 'lightgbm':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to build vignettes
      -----------------------------------
* installing *source* package 'lightgbm' ...
** using staged installation
** libs
installing via 'install.libs.R' to D:/Rtemp/RtmpYpVqer/Rinst22f027ae1107/00LOCK-lightgbm/00new/lightgbm
Error in source("install.libs.R", local = local.env) :
  install.libs.R:142:45: unexpected symbol
141: # NOTE: build_r.R replaces the line below
142: command_line_args <- c("-DBOOST_LIBRARYDIR="Clocalboost_1_78_0lib64
                                                 ^
* removing 'D:/Rtemp/RtmpYpVqer/Rinst22f027ae1107/lightgbm'
      -----------------------------------
ERROR: package installation failed
Error in .run_shell_command("R", r_build_args) :
  Command failed with exit code: 1
Execution halted

D:\LightGBM>Rscript build_r.R --use-gpu --boost-librarydir=/C/local/boost_1_78_0/lib64-msvc-14.3 --boost-root=/c/local/boost_1_78_0
* checking for file 'D:/LightGBM/lightgbm_r/DESCRIPTION' ... OK
* preparing 'lightgbm':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to build vignettes
      -----------------------------------
* installing *source* package 'lightgbm' ...
** using staged installation
** libs
installing via 'install.libs.R' to D:/Rtemp/RtmpSu6IWN/Rinst4c7c375ab3d/00LOCK-lightgbm/00new/lightgbm
Error in source("install.libs.R", local = local.env) :
  install.libs.R:142:82: unexpected string constant
141: # NOTE: build_r.R replaces the line below
142: command_line_args <- c("-DBOOST_LIBRARYDIR="/C/local/boost_1_78_0/lib64-msvc-14.3""
                                                                                      ^
* removing 'D:/Rtemp/RtmpSu6IWN/Rinst4c7c375ab3d/lightgbm'
      -----------------------------------
ERROR: package installation failed
Error in .run_shell_command("R", r_build_args) :
  Command failed with exit code: 1
Execution halted

What am I doing wrong?

Environment info

Windows 10 Home 64 Intel i7-8700K NVIDIA RTX 3080 NVIDIA CUDA 11.6 CMake 3.23 VS 2022 Boost 1.7.8 for lib64-msvc-14.3 R 4.2.0 alpha Rtools42

git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
Rscript build_r.R ...

About this issue

Most upvoted comments

@ruddnr has posted another reproducible example showing this issue on v4.3.0: #6289

I have not personally had time to investigate this further, and might not for a while. We’re still struggling with a significant lack of maintainer availability in this project, and there are some other issues occupying my time.

I’m happy to answer questions and help with reviews, but can’t devote time to testing a fix for this at the moment. We’d greatly appreciate if someone watching this thread would volunteer to try to fix this in a way that works for both Windows and Unix-likes (#5960).

As a starting point… the fix probably requires changes to some subset of these 3 files:

None of those errors, but it is still finding the wrong Boost

Nice, thanks for checking that!

Totally understood. Like I mentioned above, I didn’t expect #5607 to fix the “wrong Boost” issue yet. Just trying to fix one issue at a time 😅

Thanks for the nudge and sorry for the delay @aadler ! I also really appreciate “hey even as of the most recent commit this is still a bug” more than those “any updates?” types of comments people leave sometimes 😍

It’s hard for me to test this (and possible fixes) because I don’t have easy access to a Windows environment, but will try to get to it soon if no other maintainers do.

Visual Studio 17 2022 support was added in #4889.

If you’re building from source on v3.3.2, you could try manually adding the following line to R-package/src/install.libs.R.

https://github.com/microsoft/LightGBM/blob/b462d0a40f6978c0a66a47af4522c2ae12532316/R-package/src/install.libs.R#L68