简体   繁体   中英

Object files in R-package too large (Rcpp)

I am using Rcpp to integrate C++ code into an R-package. After compiling, I see that the *.o files are huge (~2Mb), while the original *.cpp and *.h files are only ~20kb. Where does this difference come from? I had previously implemented similar functionality without Rcpp and the *.o files where not nearly as big. With this file size, my package exceeds the allowed 4Mb from check().

As stated in the answer to this question , there are several reasons why a C++ compiled object might be that large. In the Rcpp case, the probable reason as Dirk Eddelbuettel writes in this post are the shared libraries.

My suggestion is to follow @coatless comment and create a Makevars file inside the package's package/src (you can copy the ones from the rcopulib package) to specify compiler options for the shared libraries (those .h that might get called upon several times).

Or you can copy the following code for your Makevars:

strippedLib: $(SHLIB)
        if test -e "/usr/bin/strip" & test -e "/bin/uname" & [[ `uname` == "Linux" ]] ; then /usr/bin/strip --strip-debug $(SHLIB); fi
.phony: strippedLib

as Dirk's answer has a problem with OSX as mentioned in this discussion .

As an additional note:

Be careful with the tabulations and spaces in the Makevars (they mean something). Specifically, the second line are 2 tabs (not spaces).

Replying to Rodrigo's answer here as I do not have enough reputation to comment.

I included this in the makevars of my agtboost R-package, but CRAN maintainers complained. I got the following e-mail:

The CRAN policy contains

- Packages should not attempt to disable compiler diagnostics, nor to
remove other diagnostic information such as symbols in shared objects.

With the warning that the package will be removed from CRAN if action is not taken.

Thus, it might be best to take the Note, and explain to CRAN maintainers that the reason is due to large C++ compiled objects. Note that from R>=3.6.0, the following is possible, but that the user actively have to make this choice during installation

R CMD install --strip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM