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

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Wed Dec 11 14:19:09 CET 2019


On 11 December 2019 at 14:07, Guido Kraemer 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?

Yes, a known issue with C++.  I blogged about it a few times

  http://dirk.eddelbuettel.com/blog/2019/03/27#021_stripping_take_three
  http://dirk.eddelbuettel.com/blog/2017/08/20#010_stripping_shared_libraries
  http://dirk.eddelbuettel.com/blog/2017/08/14#009_compact_shared_libraries

But CRAN does not allow stripping; just this week I updated a package at
their request removing a strip invocation.  So I think you can only add the
instructions _locally_ in ~/.R/Makevars -- I have this

  STRIP=-Wl,-S
  SHLIB_CXXLDFLAGS = $(STRIP) -shared
  SHLIB_CXX11LDFLAGS = $(STRIP) -shared
  SHLIB_CXX14LDFLAGS = $(STRIP) -shared
  SHLIB_FCLDFLAGS = $(STRIP) -shared
  SHLIB_LDFLAGS = $(STRIP) -shared

but not in shipped packages going e.g. to CRAN. 

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org



More information about the R-package-devel mailing list