[R-pkg-devel] Changing optimization level when building package?

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Tue Jul 5 15:35:05 CEST 2022


I'm trying to track down a segfault in rgl on macOS, so I need to load R 
under lldb and set breakpoints in the C++ code, examine local variables, 
etc.  Reading WRE, I thought setting CXXFLAGS=-O0 in ~/.R/Makevars would 
do minimal optimization, but I'm still getting messages about local 
variables being optimized out.  For example, here's what I see during 
compiling:

   clang++ -mmacosx-version-min=10.13 -std=gnu++11 
-I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG 
-DHAVE_PNG_H -I/usr/local/Cellar/libpng/1.6.37/include/libpng16 -DDarwin 
-I/opt/X11/include -DHAVE_FREETYPE -Iext/ftgl 
-I/usr/local/opt/freetype/include/freetype2 -Iext  -I/usr/local/include 
-O0 -fPIC  -Wall -g -O2  -c x11gui.cpp -o x11gui.o

I see the -O0 option that I added, but afterwards -O2 coming from 
somewhere in R.  I believe the second one has precedence, because I see 
this in lldb:

   (lldb) p fontnames
   error: Couldn't materialize: couldn't get the value of variable 
fontnames: no location, value may have been optimized out

If I manually run the clang++ line after editing the -O2 to -O0 before 
rebuilding, I don't have this problem, but that's really tedious.

So, my question:  how should I be asking R CMD INSTALL to use -O0?

Duncan Murdoch



More information about the R-package-devel mailing list