Simon:

Now I'm having trouble getting R to compile at all. I now set up my config.site file to something "bare bones."

CC='gcc-4.2 -arch x86_64'
OBJC='gcc-4.2 -arch x86_64'
F77='gfortran -arch x86_64'
CXX='g++-4.2 -arch x86_64'
FC='gfortran -arch x86_64'

I then use the same configure script as before. I can compile, but then 'make check' fails with

BRAUNM2: ~/Downloads/R-2.9.0 $ make check

Collecting examples for package ‘base’
Running examples in package ‘base’
/Users/braunm/Downloads/R-2.9.0/bin/BATCH: line 59: 22777 Segmentation fault ${R_HOME}/bin/R -f ${in} ${opts} ${R_BATCH_OPTIONS} > $ {out} 2>&1
Error: testing 'base' failed
Execution halted


Regardless, I did a sudo make install, and can still launch R, and load my shared libraries (no profiling, obviously).

Next, as suggested, I added a single line to config.site:

LDFLAGS='-g -pg'


'make' fails at the line

gcc-4.2 -arch x86_64 -std=gnu99 -dynamiclib -Wl,- headerpad_max_install_names -undefined dynamic_lookup -single_module - multiply_defined suppress -g -pg -install_name libR.dylib - compatibility_version 2.9.0 -current_version 2.9.0 - headerpad_max_install_names -o libR.dylib CConverters.o CommandLineArgs.o Rdynload.o Renviron.o RNG.o apply.o apse.o arithmetic.o array.o attrib.o base.o bind.o builtin.o character.o coerce.o colors.o complex.o connections.o context.o cov.o cum.o dcf.o datetime.o debug.o deparse.o deriv.o devices.o dotcode.o dounzip.o dstruct.o duplicate.o engine.o envir.o errors.o eval.o format.o fourier.o gevents.o gram.o gram-ex.o gramRd.o graphics.o identical.o inspect.o inlined.o internet.o iosupport.o lapack.o list.o localecharset.o logic.o main.o mapply.o match.o memory.o model.o names.o objects.o optim.o optimize.o options.o par.o paste.o pcre.o platform.o plot.o plot3d.o plotmath.o print.o printarray.o printvector.o printutils.o qsort.o random.o regex.o registration.o relop.o rlocale.o saveload.o scan.o seq.o serialize.o size.o sort.o source.o split.o sprintf.o startup.o subassign.o subscript.o subset.o summary.o sysutils.o unique.o util.o version.o vfonts.o xxxpr.o ../ unix/Rembedded.o ../unix/libunix.a ../appl/libappl.a ../nmath/ libnmath.a ../extra/bzip2/libbz2.a ../extra/pcre/libpcre.a ../extra/ intl/libintl.a -L../../lib/x86_64 -lRblas -lgcrt1.o -L/usr/local/lib/ gcc/i686-apple-darwin8/4.2.3/x86_64 -L/usr/local/lib/x86_64 -L/usr/ local/lib/gcc/i686-apple-darwin8/4.2.3 -L/usr/local/lib -lgfortran - Wl,-framework -Wl,CoreFoundation -lreadline -lz -licucore -lm

ld: duplicate symbol dyld_stub_binding_helper in /usr/lib/gcrt1.o and / usr/lib/dylib1.10.5.o
collect2: ld returned 1 exit status


The same thing happens if I put the -g -pg flags in MAIN_LDFLAGS


As you can probably tell, I'm new to working with C, and I'm still learning the finer points of compilers and linkers. Thanks again for helping me figure out what's going on here.

Michael



On Jun 14, 2009, at 10:22 AM, Simon Urbanek wrote:


On Jun 13, 2009, at 5:58 PM, Michael Braun wrote:

Simon:

Sorry, please disregard my last email. Shark was crashing because some of something with Shark, not R. But unfortunately, the Unknown Libraries remain.

Here is how I compiled R.  In the config.site file, I set:

R_PAPERSIZE=letter
R_BATCHSAVE=--no-save
CC='gcc-4.2 -arch x86_64 -m64 -march=core2 -msse3 -g -pg -O2'
OBJC='gcc-4.2 -arch x86_64 -m64 -march=core2 -msse3 -g -pg -O2'
DEFS=-DHAVE_INLINE
F77='gfortran -arch x86_64 -g -pg -O2'
LIBnn=lib
CXX='g++-4.2 -arch x86_64 -march=core2 -p -pg -O2'
FC='gfortran -arch x86_64 -m64 -march=core2 -g -pg -O2'
TCLTK_LIBS=/usr/lib

To configure, I ran the following script

#!/bin/bash

./configure \
SHELL='/bin/bash' \
r_arch=x86_64 \
--with-system-zlib \
--with-blas='-framework vecLib' --with-lapack='-framework vecLib' \
--with-ICU \
--with-aqua \
--enable-R-framework \
--enable-BLAS-shlib \
--with-x \
--with-readline=/usr/local \
--with-tcltk \
--with-iconv=no \
--with-cairo \
--disable-R-profiling \
--with-recommended-packages=no


Any idea what I did wrong?


You didn't set -pg for link-time* which is the crucial one (adding - pg to compile flags is not strictly necessary unless you want to profile R itself).

Also you may want to tweak the flags (CFLAGS et al.) instead of the compilers since they have higher precedence (also you have a typo in CXX). [And why the DEFS?]

Always check the output when your library is actually compiled - you may find your flags being overridden by others.

Cheers,
Simon


* you can use LDFLAGS or LIBS but in this instance MAIN_LDFLAGS may be more interesting, but I didn't test it.


Thanks,

Michael



On Jun 12, 2009, at 7:27 PM, Simon Urbanek wrote:

Michael,

On Jun 12, 2009, at 4:20 PM, Michael Braun wrote:

Hi. I have a shared library that I would like to profile. I see that this issue has been touched on in some previous posts, but I am still having trouble, and I am hoping someone here can help.

First things first... I am running R 2.8.0 patched on OS X 10.5.7, on a dual quad-core Mac Pro. It is the 64-bit binary build for Leopard, as downloaded from CRAN.

I am compiling my code using gcc-4.2, and I am including the -g - p -pg flags.

The -p -pg part (they are mutually-exclusive aren't they? so you get just -pg) won't really help unless you also compile R that way since the gprof initialization happens in the executable, not in the library (and don't forget it at link time).


Optimization is turned off (-O0).

Just to make sure - using PKG_CFLAGS doesn't have the desired effect, because R's -O2 will override it, so better be sure that the optimization is off. If you run the steps manually, make sure you have -g (and -pg if you wish) everywhere.


I AM able to debug the code using gdb (called as R -d gdb). I always run R from the command line.

I have tried profiling using Shark, which recognizes functions in libR.dylib, but none of the functions in mylib.so. For each function call, Shark refers to "Unknown Library", and after the function address, there is an indicator of [unknown]. Also, when I use Shark, it appears to want to profile the entire R session. All I care about is my library.


I'm unable to replicate that. Shark correctly recognizes the function and the loaded library for me. Try using default flags - they do include -g -O2 (which worked for me).


I am also open to using gprof instead, but I cannot find the requisite gmon.out file.


See above - you won't find it unless you compile R with -pg since the gprof init code must be in the executable (more precisely you don't have to re-compile the entire R with that, it should be sufficient to use -pg in the link step for exec/R).

Cheers,
Simon


Thanks in advance for any suggestions.

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
bra...@mit.edu
617-253-3436

_______________________________________________
R-SIG-Mac mailing list
R-SIG-Mac@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-mac




-------------------------------------------
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
bra...@mit.edu
617-253-3436







-------------------------------------------
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
bra...@mit.edu
617-253-3436

_______________________________________________
R-SIG-Mac mailing list
R-SIG-Mac@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Reply via email to