Hello, I'm writing an R package that is mainly written in C++. By default, R CMD INSTALL creates C/C++ flags as follows: -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g However, my package is fairly large. With debug info compiled into the library, the generated .so file is over 200MB. Without debug info, it's about 30MB. I hope by default debug info is disabled. However, I don't see any option in R CMD INSTALL that can disable "-g". Could anyone tell me how to disable it? Many thanks, Da
On 16 October 2016 at 09:46, Da Zheng wrote: | I'm writing an R package that is mainly written in C++. By default, R | CMD INSTALL creates C/C++ flags as follows: | -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat | -Werror=format-security -D_FORTIFY_SOURCE=2 -g That looks like you are running R on a Debian or Ubuntu system as these are the compilation defaults we set everywhere, and which my r-base-core package has via the same defaults. That is also where the `-g` comes from. By default we compile everything with debugging, and (these days) strip debug symbols away in a -dbg package. I.e. if you wanted to use gdb to analyse R you could without recompilation by just installing the r-base-core-dbg package. That is a nice feature. | However, my package is fairly large. With debug info compiled into the | library, the generated .so file is over 200MB. Without debug info, | it's about 30MB. I hope by default debug info is disabled. You cannot, currently. The values in Makeconf (for us in /etc/R/Makeconf) cannot be edited before `R CMD INSTALL` et al use them. That is a pity, but such is life. We had prior discussions about this here; and at least Simon chimed in once and confirmed. | However, I don't see any option in R CMD INSTALL that can disable | "-g". Could anyone tell me how to disable it? You cannot, currently. There are a few ways out: i) Quick local fix: Edit /etc/R/Makeconf. Obviously not portable. ii) Rebuild R without -g in the configure flags. Ditto. iii) Do something in src/Makevars to strip after the build. May be flagged as non-portable by CRAN but at least it tries. iv) (Lot of work, potentially) Patch the R build system to allow, say, sed filtering of some of the values in Makeconf. Get the patch included. Hope this helps, Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Hello Dirk, Thank you very much for your reply. The main reason I want to remove the debug info is that when I use R CMD check on my package, it gives the following info * checking installed package size ... NOTE installed size is 223.6Mb sub-directories of 1Mb or more: libs 223.1Mb CRAN requires an R package to pass all checks and fix all complaints including NOTEs. It seems R's default compilation options significantly increase the library size. Do you have any suggestions on fixing this NOTE? Thanks, Da On Sun, Oct 16, 2016 at 10:09 AM, Dirk Eddelbuettel <edd at debian.org> wrote:> > On 16 October 2016 at 09:46, Da Zheng wrote: > | I'm writing an R package that is mainly written in C++. By default, R > | CMD INSTALL creates C/C++ flags as follows: > | -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat > | -Werror=format-security -D_FORTIFY_SOURCE=2 -g > > That looks like you are running R on a Debian or Ubuntu system as these are > the compilation defaults we set everywhere, and which my r-base-core package > has via the same defaults. > > That is also where the `-g` comes from. By default we compile everything > with debugging, and (these days) strip debug symbols away in a -dbg package. > > I.e. if you wanted to use gdb to analyse R you could without recompilation by > just installing the r-base-core-dbg package. That is a nice feature. > > | However, my package is fairly large. With debug info compiled into the > | library, the generated .so file is over 200MB. Without debug info, > | it's about 30MB. I hope by default debug info is disabled. > > You cannot, currently. > > The values in Makeconf (for us in /etc/R/Makeconf) cannot be edited before `R > CMD INSTALL` et al use them. That is a pity, but such is life. We had prior > discussions about this here; and at least Simon chimed in once and confirmed. > > | However, I don't see any option in R CMD INSTALL that can disable > | "-g". Could anyone tell me how to disable it? > > You cannot, currently. > > There are a few ways out: > > i) Quick local fix: Edit /etc/R/Makeconf. Obviously not portable. > > ii) Rebuild R without -g in the configure flags. Ditto. > > iii) Do something in src/Makevars to strip after the build. May be > flagged as non-portable by CRAN but at least it tries. > > iv) (Lot of work, potentially) Patch the R build system to allow, say, > sed filtering of some of the values in Makeconf. Get the patch > included. > > Hope this helps, Dirk > > -- > http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Hi, As I know, a solution is customizing Makefile target by yourself in src/Makevars of your package, and removing the -g option. As an example, you can see https://github.com/SimonYansenZhao/wsrf/blob/09b197ed79b1c55a95d52b14aa5db3437f75f930/src/Makevars I paste that here. See "$(CXX1XFLAGS:-g=)" below. CXX_STD = "CXX11" PKG_LIBS = `"$(R_HOME)/bin/Rscript" -e "Rcpp:::LdFlags()"` -pthread wsrf_FLAGS = $(R_XTRA_CPPFLAGS) $(PKG_CPPFLAGS) $(CPPFLAGS) $(CLINK_CPPFLAGS) $(R_XTRA_CXXFLAGS) $(PKG_CXXFLAGS) $(CXX1XPICFLAGS) $(SHLIB_CXXFLAGS) $(CXX1XFLAGS:-g=) $(CXX1XSTD) all: $(SHLIB) %.o: %.cpp $(SHLIB_CXX1XLD) $(wsrf_FLAGS) -c $< -o $@ However, I am not sure if it is allowed on CRAN, and I think it must have a reason for that, though I don't know. So I didn't do that in my package. Best regards, Simon(??) On 2016?10?16? 21:46, Da Zheng wrote:> Hello, > > I'm writing an R package that is mainly written in C++. By default, R > CMD INSTALL creates C/C++ flags as follows: > -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat > -Werror=format-security -D_FORTIFY_SOURCE=2 -g > > However, my package is fairly large. With debug info compiled into the > library, the generated .so file is over 200MB. Without debug info, > it's about 30MB. I hope by default debug info is disabled. However, I > don't see any option in R CMD INSTALL that can disable "-g". Could > anyone tell me how to disable it? > > Many thanks, > Da > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel