From uwe_f_mayer at yahoo.com  Fri Aug 21 17:55:13 2009
From: uwe_f_mayer at yahoo.com (uwe_f_mayer at yahoo.com)
Date: Fri, 21 Aug 2009 17:55:13 +0200 (CEST)
Subject: [Rd] R installation problem with shared libraries (PR#13900)
Message-ID: <20090821155513.1504B283200A@mail.pubhealth.ku.dk>

Full_Name: Uwe F. Mayer
Version: 2.9.1
OS: SunOS myhost 5.10 Generic_120012-14 i86pc i386 i86pc Solaris
Submission from: (NULL) (216.113.168.130)


Configuration problem with the creation of shared libraries: Compilation only
succeeds if SHLIB_LDFLAGS="-shared" is added to the configure command line. This
is likely due to a wellknown gcc-4 feature, in that gcc requires -shared and not
just the linker flag -G to generate dynamically loaded libraries. However, even
if this variable is set at configuration time, it is not properly propagated to
the installed version, and one needs to patch the final installed version.

Specifics:

gcc -v 
Using built-in specs.
Target: x86_64-pc-solaris2.10
Configured with: ../../src/gcc-4.4.0/configure
--prefix=/usr/local/opt/x86_64-pc-solaris2.10/gcc-4.4.0
--with-gmp=/usr/local/opt/x86_64-pc-solaris2.10
--with-mpfr=/usr/local/opt/x86_64-pc-solaris2.10 --disable-nls
--enable-languages=c,c++,fortran -with-gnu-as --without-gnu-ld
--with-ld=/usr/ccs/bin/ld --with-as=/usr/sfw/bin/gas CC='gcc -m64' CXX='g++
-m64' CFLAGS='-m64 -g -O2' CXXFLAGS='-m64 -g -O2' LDFLAGS=-m64
Thread model: posix
gcc version 4.4.0 (GCC) 

R version: 2.9.1 (2009-06-29)

R configuration
../../src/R-2.9.1/configure
--prefix=/usr/local/opt/x86_64-pc-solaris2.10/R-2.9.1
--exec-prefix=/usr/local/opt/x86_64-pc-solaris2.10/R-2.9.1 --disable-nls
--without-recommended-packages --with-readline --with-gnu-ld CC="gcc -m64
-I/usr/local/opt/x86_64-pc-solaris2.10/include
-L/usr/local/opt/x86_64-pc-solaris2.10/lib" F77="gfortran -m64" CXX="g++ -m64"
FC="gfortran -m64" LIBnn=lib64 LD=/usr/local/opt/x86_64-pc-solaris2.10/bin/ld

When the newly built R is called by gmake during the build process, it throws an
error:

gmake[4]: Leaving directory `/usr/local/opt/build/R-2.9.1/src/library/base'
ld.so.1: R: fatal: relocation error: R_AMD64_PC32: file
/usr/local/opt/build/R-2.9.1/lib/libRblas.so: symbol main: value 0x280010fd8f4
does not fit
/bin/bash: line 1: 29055 Done                    cat
../../../../../src/R-2.9.1/src/library/base/makebasedb.R
     29056 Killed                  | R_DEFAULT_PACKAGES=NULL LC_ALL=C
../../../bin/R --vanilla --slave >/dev/null
gmake[3]: *** [all] Error 137

As said, adding SHLIB_LDFLAGS="-shared" to the configure command fixes this
problem.

Even with this fix I also ran into a similar problem down the line when
compiling packages (specifically e1071), and it turns out that even if
specified, the flag is not fully propagated to the final installed version. I
found myself applying the following patch the final installed 2.9.1 version:

patch /usr/local/opt/x86_64-pc-solaris2.10/R-2.9.1/lib64/R/etc/Makeconf <<EOF
71c71
< SHLIB_CXXLDFLAGS = -G
---
> SHLIB_CXXLDFLAGS = -shared -G
EOF

Here is an example that triggers this error (just use any lazy-load package that
depends on another lazy-load package which had used g++ for the final linking
step).

> install.packages("e1071")
[***many lines cut***]
gcc -m64 -I/usr/local/opt/x86_64-pc-solaris2.10/include -L/usr/local
/opt/x86_64-pc-solaris2.10/lib -std=gnu99 -I/usr/local/opt/x86_64-pc-solar
is2.10/R-2.9.1/lib64/R/include  -I/usr/local/include    -fpic  -g -O2 -c
floyd.c
 -o floyd.o
g++ -m64 -I/usr/local/opt/x86_64-pc-solaris2.10/R-2.9.1/lib64/R/include  -
I/usr/local/include    -fpic  -g -O2 -c svm.cpp -o svm.o
g++ -m64 -G -L/usr/local/lib64 -o e1071.so Rsvm.o cmeans.o cshell.o floyd.o
svm.
o
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
 >>> Building/Updating help pages for package 'e1071'
     Formats: text html latex example 
  Discrete                          text    html    latex   example
[***many lines cut***]
  write.svm                         text    html    latex   example
** building package indices ...
* DONE (e1071)
The downloaded packages are in
        '/tmp/Rtmp55ohkF/downloaded_packages'

> install.packages("PSAUR")
trying URL 'http://lib.stat.cmu.edu/R/CRAN/src/contrib/PASWR_1.0.tar.gz'
Content type 'application/x-gzip' length 134976 bytes (131 Kb)
opened URL
==================================================
downloaded 131 Kb

* Installing *source* package 'PASWR' ...
** R
** data
**  moving datasets to lazyload DB
** preparing package for lazy loading
Loading required package: class
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared library '/home/myuser/R/x86_64-pc-solaris2.10-library/
2.9/e1071/libs/e1071.so':
  ld.so.1: R: fatal: relocation error: R_AMD64_PC32: file /home/myuser/R/x86_6
4-pc-solaris2.10-library/2.9/e1071/libs/e1071.so: symbol main: value
0x2800256b1
a4 does not fit
Error : package 'e1071' could not be loaded
ERROR: lazy loading failed for package 'PASWR'



[Rd] R installation problem with shared libraries (PR#13900)
uwe_f_mayer at yahoo.com