[R-pkg-devel] reduce size of shared objects

Guido Kraemer gkr@emer @end|ng |rom bgc-jen@@mpg@de
Wed Dec 11 15:01:02 CET 2019


I have tried the suggestion from the blog post and added

|strippedLib: $(SHLIB) if test -e "/usr/bin/strip" & test -e 
"/bin/uname" & [[ `uname` == "Linux" ]] ; \ then /usr/bin/strip 
--strip-debug $(SHLIB); fi .phony: strippedLib|
||
||
|to `src/Makevars` and it works great, it gets the size of the shared 
object down to 1.3 Mb.|
|When submitting this to CRAN some day, should I apply this trick or 
ignore it and let the user|
|decide with the new ``R CMD install --strip`` option in R 3.6? Cheers, 
Guido |

||
|
|
On 12/11/19 2:25 PM, Guido Kraemer wrote:
> Thanks, I wasn't aware about these blog posts. I have just read a 
> little bit of gcc documentation and the `-flto` flag has to be 
> provided also in the compile steps, doing this
>
> PKG_CPPFLAGS=-I"../inst/include" -flto
> PKG_LIBS=-lstdc++fs -flto
>
> reduces the size of the final `.so` to under 1Mb, but gives a warning 
> in `R CMD check --as-cran` because `-flto` doesn't seem to be portable.
>
> Cheers,
>
> Guido
>
> On 12/11/19 2:15 PM, Iñaki Ucar wrote:
>> On Wed, 11 Dec 2019 at 14:07, Guido Kraemer 
>> <gkraemer using bgc-jena.mpg.de> wrote:
>>> I am building an R package (https://github.com/gdkrmr/zarr-R) that 
>>> wraps
>>> a couple of C++ headers and the resulting shared object is huge (>20Mb,
>>> see https://travis-ci.org/gdkrmr/zarr-R). I have tried to set the
>>> following in `./src/Makevars`:
>>>
>>> PKG_CPPFLAGS=-I"../inst/include" -ffunction-sections -fdata-sections
>>> PKG_LIBS=-lstdc++fs -flto -Wl,--gc-sections
>>>
>>> but this does not reduce the size of the shared object and produces 
>>> some
>>> warnings in `R CMD check` due to portability issues. Is there a way to
>>> reduce the size of the shared object or do I just have to live with it?
>> Hi, see Dirk's http://dirk.eddelbuettel.com/blog/2019/03/27/ and
>> related posts (linked in the first paragraph).
>>
>> Iñaki
>
-- 
Guido Kraemer
Max Planck Institute for Biogeochemistry Jena
Department for Biogeochemical Integration
Hans-Knöll-Str. 10
07745 Jena
Germany

phone: +49 3641 576293
e-mail: gkraemer using bgc-jena.mpg.de



More information about the R-package-devel mailing list