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

Sokol Serguei @ergue|@@oko| @end|ng |rom gm@||@com
Tue Jul 5 15:53:42 CEST 2022


Le 05/07/2022 à 15:35, Duncan Murdoch a écrit :
> 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?

I use the following "hakish" solution: add in your Makevars something 
similar to:

MYFLAGS=-g -O0
%.o: %.cpp
     $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) $(MYFLAGS) -c $< -o $@
%.o: %.c
     $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(MYFLAGS) -c $< -o $@
%.o: %.F
     $(FC) $(ALL_FCFLAGS) $(MYFLAGS) -c $< -o $@

Best,
Serguei.

>
> Duncan Murdoch
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list