[Rd] Turning off compiler optimization

Dirk Eddelbuettel edd at debian.org
Thu Nov 20 22:09:41 CET 2008


On 20 November 2008 at 15:25, Michael Braun wrote:
| Hi.  I am writing some code in C that I would like to link into R.
| 
| My Makevars file is:
| 
| PKG_CPPFLAGS=-I/usr/local/include
| PKG_LIBS=-L/usr/local/lib -lgsl
| PKG_CFLAGS = -Wall -O0 -g -p -pg
| 
| The source file is core.c,. and I am compiling using R CMD SHLIB  
| core.c  The output is
| 
| gcc -arch x86_64 -O3 -g -p -std=gnu99 -I/Library/Frameworks/ 
| R.framework/Resources/include -I/Library/Frameworks/R.framework/ 
| Resources/include/x86_64 -I/usr/local/include -I/usr/local/include   - 
| Wall -O0 -g -p -pg -fPIC  -g -O2 -c core.c -o core.o
| 
| gcc -arch x86_64 -O3 -g -p -std=gnu99 -dynamiclib -Wl,- 
| headerpad_max_install_names  -undefined dynamic_lookup -single_module - 
| multiply_defined suppress -L/usr/local/lib -o core.so core.o -L/usr/ 
| local/lib -lgsl  -F/Library/Frameworks/R.framework/.. -framework R - 
| Wl,-framework -Wl,CoreFoundation
| 
| I am running R 2.7.1 on a Mac Pro (Intel-based) with OS X 10.5.5.
| 
| My problem is that, for debugging purposes, I would like to turn off  
| compiler optimization (so gdb stops telling me that values are  
| temporarily unavailable due to optimizations).  I thought I was doing  
| that by putting the -O0 flag in PKG_CFLAGS in the Makevars file.  But  
| from the output, it looks like there is still some optimization going  
| on.  I would also like to avoid writing a Make file from scratch, if  
| at all possible.
| 
| I looked through the documentation and archives, and was unable to  
| find a solution to this.  Can someone offer some assistance?

One way is to edit $RHOME/etc/Makeconf by hand and remove the settings left
there from the build-time configuration.

Another way is to not use R CMD SHLIB but to craft a simple Makefile,
copying the same commands that R CMD SHLIB shows you, and editing what you
want to change. I often to that for development.

Hth, Dirk

-- 
Three out of two people have difficulties with fractions.



More information about the R-devel mailing list