My package .so
file is above 3 MB (up to 10 MB) depending of the compiler and the system. This generates a NOTE with R CMD check
in my package for years. My package does not contain so much code so I eventually searched to reduce the size and I found this excellent post by Dirk Eddelbuettel.
Following the advice I added SHLIB_CXX11LDFLAGS = -Wl,-S -shared
in my .R/Makevars
and my library size dropped from 10.4 MB to 580 KB!! For the first time I have 0 ERRORS, 0 WARNINGS and 0 NOTES. Yeah!
However this is only a local solution. At the end of the post the following is suggested for src/Makevars
strippedLib: $(SHLIB)
if test -e "/usr/bin/strip"; then /usr/bin/strip --strip-debug $(SHLIB); fi
.phony: strippedLib
But it is mentioned that:
And this scheme may even pass muster with CRAN, but I have not yet tried.
My questions are the following:
AFAIK you cannot put it in src/Makevars
. I just had to revert this myself in a package where the powers-that-be noticed it.
But then, confusingly, we also have
edd@rob:~$ grep -i strip /etc/R/Makeconf # convenience softlink on Debian/Ubuntu
STRIP_STATIC_LIB = strip --strip-debug
STRIP_SHARED_LIB = strip --strip-unneeded
edd@rob:~$
but I haven't yet had time to search if/where these are used. So I still do
edd@rob:~$ grep -i strip ~/.R/Makevars
STRIP=-Wl,-S
SHLIB_CXXLDFLAGS = $(STRIP) -shared
SHLIB_CXX11LDFLAGS = $(STRIP) -shared
SHLIB_CXX14LDFLAGS = $(STRIP) -shared
SHLIB_FCLDFLAGS = $(STRIP) -shared
SHLIB_LDFLAGS = $(STRIP) -shared
edd@rob:~$
which is local-only.
Edit: Something I keep forgetting is the recently added --strip
option for the installer:
edd@rob:~$ R CMD INSTALL --help | grep strip
--strip strip shared object(s)
edd@rob:~$
which can also be enable by setting the environment variable _R_SHLIB_STRIP_
to a true value -- see a recent NEWS file for R.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With