From khansen at stat.berkeley.edu  Thu Nov 20 22:02:34 2008
From: khansen at stat.berkeley.edu (Kasper Daniel Hansen)
Date: Fri, 21 Nov 2008 08:02:34 +1100
Subject: [Rd] Turning off compiler optimization
In-Reply-To: <8EB66ACA-70E3-4F4C-9F1E-695C44882179@mit.edu>
References: <8EB66ACA-70E3-4F4C-9F1E-695C44882179@mit.edu>
Message-ID: <17C77B25-DF5F-4F18-B422-B56C09365E33@stat.berkeley.edu>

This is what I am using, suggested a long time ago by Simon Urbanek. I  
would really like a good way way to override optimization flags - in  
my package I have code that does not work with -O2. I use the  
following lines in my Makevars

MYCXXFLAGS=-O0

%.o: %.cpp
         $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) $(MYCXXFLAGS) -c $< -o  
$@

Kasper

On Nov 21, 2008, at 7: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?
>
> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Turning off compiler optimization
Kasper Daniel Hansen