[R-package] replaced gendef.exe with R code to create R.def (fixes #3064) #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Experimental fix for microsoft#3064.
Short description
Building the
LightGBM
R package on Windows with Visual Studio compilers requiresgendef.exe
. That was bundled in previous versions ofRTools
but isn't part ofRTools
4.0.This PR replaces it with an R script that uses
objdump.exe
, software bundled in old and new distributions ofRTools
.How you can test this
In a Windows environment with R 4.0, RTools 4.0, CMake, and Visual Studio, run the following:
Long Description
Here's how building the R package with Visual Studio works today:
R.dll
to use R-provided C/C++ functions such asRprintf
for printing..lib
file (https://docs.microsoft.com/en-us/cpp/build/reference/link-input-files?redirectedfrom=MSDN&view=vs-2019).lib
file fromR.dll
on Windows, we create a definition file (.def
) and then use that to make a library file (.lib
).R.dll
ships with RR.def
is created fromR.dll
, usinggendef.exe
R.lib
is created fromR.def
usingdlltool.exe
The issue:
gendefe.exe
is not part of RTools 4.0.My solution in this PR is to use
objdump.exe
+ an R script to generateR.def
.objdump
creates output intended for humans not machines...it uses indentation and special chracters to make the file visually appealing. So the R script is used to runobjdump
, but more importantly to read in the text it produces and do some simple cleaning to get it into a machine-friendly format that can be re-written as a.def
file.From the "How to create a def file from a dll" section of this amazing MinGW documentation.
References
A lot of the content for this PR was totally new to me. Here are some links I found very helpful.
.def
file: text file that contains the names of objections exported from a DLL.lib
file: a library file, basically a specific format that describe DLL so a linker understands how to link to it