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
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
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.
Use .R/Makeconf: see 'R Installation and Administration' section 6.3.3. On Thu, 20 Nov 2008, 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-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595