From braunm at MIT.EDU  Thu Nov 20 21:25:16 2008
From: braunm at MIT.EDU (Michael Braun)
Date: Thu, 20 Nov 2008 15:25:16 -0500
Subject: [Rd] Turning off compiler optimization
Message-ID: <8EB66ACA-70E3-4F4C-9F1E-695C44882179@mit.edu>

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?

Thanks,

Michael



-------------------------------------------
Michael Braun
Homer A. Burnell Career Development Professor, and
	Assistant Professor of Management Science (Marketing Group)
MIT Sloan School of Management
One Amherst St., E40-169
Cambridge, MA 02142
braunm at mit.edu
617-253-3436



[Rd] Turning off compiler optimization
Michael Braun