From penel at biomserv.univ-lyon1.fr  Fri Apr  6 15:09:07 2007
From: penel at biomserv.univ-lyon1.fr (Simon Penel)
Date: Fri, 06 Apr 2007 15:09:07 +0200
Subject: [Rd] getConnection is not found in R depending on the Linux flavour
 (RedHat or Debian) - dyn.load problems
Message-ID: <46164673.8000008@biomserv.univ-lyon1.fr>


Hello R developers,

I am working on the "seqinr" package and I encounter a tricky problem 
using  a C
function.

We defined a C fonction called   "getzlibsock" which is dedicated to 
compressed
socket connections. This function is using the R internal  C function
called "getConnection(int)" in order to get information about the socket
previously opened with the dedicated R functions.

The program works fine on several platform:
-Unix (SunOS),
-MacOS and
-Linux (some).
However, on Linux, an error occurs  depending on the installation.

I tried to play with the Makevars file  by specifing lots of path and 
library
without succees
On Red Hat Linux  it works fine, but on Debian the dynamic library can 
not be
loaded:

Library is working fine with Linux  Red Hat:
---------------------------------------------------------

R.2.4.0
Linux ccali24 2.4.21-32.0.1.ELsmp #1 SMP Wed May 25 15:42:26 CDT 2005 
i686 i686 i386 GNU/Linux
RedHat
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-52)
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with:
 ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--host=i386-redhat-linux
Thread model: posix


Compiling the dynamic library:
Makevars:
PKG_CFLAGS = -ansi -DUSE_TYPE_CHECKING_STRICT

R CMD SHLIB -o test.so *.c
gcc -I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include 
-I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 
-std=gnu99 -c alignment.c -o alignment.o
gcc -I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include 
-I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 
-std=gnu99 -c getzlibsock.c -o getzlibsock.o
gcc -I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include 
-I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 
-std=gnu99 -c kaks.c -o kaks.o
gcc -I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include 
-I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 
-std=gnu99 -c util.c -o util.o
gcc -I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include 
-I/afs/in2p3.fr/home/throng/biometr/R_dir/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 
-std=gnu99 -c zsockr.c -o zsockr.o
gcc -shared -L/usr/local/lib -o test.so alignment.o getzlibsock.o kaks.o 
util.o zsockr.o  


Note that the dll libR.so is not asked not the path to the dll
Loading the dynamic library:

R version 2.4.0 (2006-10-03)
Copyright (C) 2006 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

 > dyn.load("test.so")
 >



Problem in library  with Linux Debian
--------------------------------------------------
( both  binary distribution of R and version builded from sources):



a) with the binary version
R version 2.4.1 (2006-12-18)

This the binary distribution obtained via apt-get

Linux pcstef 2.6.15-1-686-smp #2 SMP Mon Mar 6 15:34:50 UTC 2006 i686 
GNU/Linux
Debian
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Configured with:
../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix

Compiling the dynamic library:
Makevars:
PKG_CFLAGS = -ansi -DUSE_TYPE_CHECKING_STRICT
PKG_LIBS =  -lR  -lz
 rm *o
 
 
R CMD SHLIB -o test.so *.c
gcc -std=gnu99 -I/usr/share/R/include -I/usr/share/R/include     -ansi 
-DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c alignment.c -o alignment.o
gcc -std=gnu99 -I/usr/share/R/include -I/usr/share/R/include     -ansi 
-DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c getzlibsock.c -o getzlibsock.o
gcc -std=gnu99 -I/usr/share/R/include -I/usr/share/R/include     -ansi 
-DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c kaks.c -o kaks.o
gcc -std=gnu99 -I/usr/share/R/include -I/usr/share/R/include     -ansi 
-DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c util.c -o util.o
gcc -std=gnu99 -I/usr/share/R/include -I/usr/share/R/include     -ansi 
-DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c zsockr.c -o zsockr.o
gcc -std=gnu99 -shared  -o test.so alignment.o getzlibsock.o kaks.o 
util.o zsockr.o -lR  -lz  -L/usr/lib/R/lib -lR


Loading the dynamic library:
....
 > dyn.load("test.so")
Erreur dans dyn.load(x, as.logical(local), as.logical(now)) :
        impossible de charger la biblioth?que partag?e 
'/home/simon/seqinr_in2p3/seqinr/src/test.so':
  /home/simon/seqinr_in2p3/seqinr/src/test.so: undefined symbol: 
getConnection
 >
....
However  the dll libR.so exists in the "/usr/lib/R/lib" path:
ls /usr/lib/R/lib
libRlapack.so  libR.so

But the libR.so does not seems to contain getConnection:
grep getConnection /usr/lib/R/lib/libR.so  give no answer


Moreover libR.so can not be read by nm:
nm: /usr/lib/R/lib/libR.so: aucun symbole

b) with the sources

I was thus wondering if the problem was due to a incompatibility between 
the binary
version of R I get  via apt-get and the dynamic library I compiled with  the
current gcc.

I try with the R installed from sources

../../../R-install_R-2.4.1/bin/R  CMD SHLIB -o test.so *.c
gcc-4.1 -std=gnu99 -I/home/simon/R-install_R-2.4.1//lib/R/include 
-I/home/simon/R-install_R-2.4.1//lib/R/include  -I/usr/local/include   
-ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c alignment.c -o alignment.o
gcc-4.1 -std=gnu99 -I/home/simon/R-install_R-2.4.1//lib/R/include 
-I/home/simon/R-install_R-2.4.1//lib/R/include  -I/usr/local/include   
-ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c getzlibsock.c -o 
getzlibsock.o
gcc-4.1 -std=gnu99 -I/home/simon/R-install_R-2.4.1//lib/R/include 
-I/home/simon/R-install_R-2.4.1//lib/R/include  -I/usr/local/include   
-ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c kaks.c -o kaks.o
gcc-4.1 -std=gnu99 -I/home/simon/R-install_R-2.4.1//lib/R/include 
-I/home/simon/R-install_R-2.4.1//lib/R/include  -I/usr/local/include   
-ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c util.c -o util.o
gcc-4.1 -std=gnu99 -I/home/simon/R-install_R-2.4.1//lib/R/include 
-I/home/simon/R-install_R-2.4.1//lib/R/include  -I/usr/local/include   
-ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c zsockr.c -o zsockr.o
gcc-4.1 -std=gnu99 -shared -L/usr/local/lib -o test.so alignment.o 
getzlibsock.o kaks.o util.o zsockr.o -lR  -lz  
-L/home/simon/R-install_R-2.4.1//lib/R/lib -lR



Loading the dynamic library:

~/seqinr_in2p3/seqinr/src$ 
../../../R-install_R-2.4.1/bin/R                         
R version 2.4.1 (2006-12-18)
Copyright (C) 2006 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
...
 > dyn.load("test.so")
Erreur dans dyn.load(x, as.logical(local), as.logical(now)) :
        impossible de charger la biblioth?que partag?e 
'/home/simon/seqinr_in2p3/seqinr/src/test.so':
  /home/simon/seqinr_in2p3/seqinr/src/test.so: undefined symbol: 
getConnection
 >
...

In this case the path still contains 
/home/simon/R-install_R-2.4.1//lib/R/lib
where the R ldd can be found:
 ls /home/simon/R-install_R-2.4.1//lib/R/lib
libRblas.so  libRlapack.so  libR.so

and libR.so contains getConnection:
 nm  /home/simon/R-install_R-2.4.1//lib/R/lib/libR.so |grep getConnection
00052990 t getConnection
00052240 t getConnection_no_err



I was wondering if the problem was a difference between R-2.4.1 and 
R.2.4.0 but I
think this not the case because it is possible to compile and load the 
dll test.so on Linux
Red Hat with the R-devel version as well as the R-2.4.0., and it works 
fine as well on the MacOS
R-2.4.1.:


Library is working fine with MacOS:
-----------------------------------------------

R-2.4.1
Darwin chobits.univ-lyon1.fr 8.8.0 Darwin Kernel Version 8.8.0: Fri Sep  
8 17:18:57 PDT 2006; root:xnu-792.12.6.obj~1/RELEASE_PPC Power Macintosh 
powerpc
gcc: Target: i686-apple-darwin8
Configured with: ../gcc-4.0.3/configure --prefix=/usr/local/gcc4.0 
--disable-checking --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ 
--build=i686-apple-darwin8 --program-prefix=powerpc-apple-darwin8- 
--host=powerpc-apple-darwin8 --target=i686-apple-darwin8 --with-sysroot= 
--enable-languages=c,c++,f95,objc
Thread model: posix
gcc version 4.0.3


 R CMD SHLIB -o test.o *.c
gcc-4.0 -arch ppc -std=gnu99 
-I/Library/Frameworks/R.framework/Resources/include 
-I/Library/Frameworks/R.framework/Resources/include/ppc  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fPIC  -g -O2 -c 
alignment.c -o alignment.o
gcc-4.0 -arch ppc -std=gnu99 
-I/Library/Frameworks/R.framework/Resources/include 
-I/Library/Frameworks/R.framework/Resources/include/ppc  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fPIC  -g -O2 -c 
getzlibsock.c -o getzlibsock.o
gcc-4.0 -arch ppc -std=gnu99 
-I/Library/Frameworks/R.framework/Resources/include 
-I/Library/Frameworks/R.framework/Resources/include/ppc  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fPIC  -g -O2 -c 
kaks.c -o kaks.o
gcc-4.0 -arch ppc -std=gnu99 
-I/Library/Frameworks/R.framework/Resources/include 
-I/Library/Frameworks/R.framework/Resources/include/ppc  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fPIC  -g -O2 -c 
util.c -o util.o
gcc-4.0 -arch ppc -std=gnu99 
-I/Library/Frameworks/R.framework/Resources/include 
-I/Library/Frameworks/R.framework/Resources/include/ppc  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fPIC  -g -O2 -c 
zsockr.c -o zsockr.o
gcc-4.0 -arch ppc -std=gnu99 -dynamiclib -Wl -single_module 
-multiply_defined suppress -L/usr/local/lib -o test.o alignment.o 
getzlibsock.o kaks.o util.o zsockr.o   
-L/Library/Frameworks/R.framework/Resources/lib/ppc -lR -dylib_file 
libRblas.dylib:/Library/Frameworks/R.framework/Resources/lib/ppc/libRblas.dylib

R version 2.4.1 (2006-12-18)
Copyright (C) 2006 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
....
 > dyn.load("test.o")
 >
 >


R Installation problem?
-------------------------------

I was wondering if it the way in which R is configured? I installed R on 
the Linux Debian  with these options ./configure --prefix
/home/simon/R-install_R-2.4.1/ --without-dataentry --without-x 
--disable-dataentry --enable-R-shlib --enable-static
--with-recommended-packages CC=gcc-4.1

I noticed as well that concerning the  Debian Linux installations ,I 
had  problem when the libR.so  was required during compilation of my
 sources ( -lR option). I try a new installation of R with the folowing 
options:

 ./configure --prefix=/home/simon/R-2.4.1_otherinstall/install/ 
--without-dataentry --without-x --disable-dataentry --enable-static
--with-recommended-packages

When compiling my sources I get:

 rm *o
../../../R-2.4.1_otherinstall/install/bin/R CMD SHLIB -o test.o *.c
gcc -std=gnu99 -I/home/simon/R-2.4.1_otherinstall/install//lib/R/include 
-I/home/simon/R-2.4.1_otherinstall/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c 
alignment.c -o alignment.o
gcc -std=gnu99 -I/home/simon/R-2.4.1_otherinstall/install//lib/R/include 
-I/home/simon/R-2.4.1_otherinstall/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c 
getzlibsock.c -o getzlibsock.o
gcc -std=gnu99 -I/home/simon/R-2.4.1_otherinstall/install//lib/R/include 
-I/home/simon/R-2.4.1_otherinstall/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c 
kaks.c -o kaks.o
gcc -std=gnu99 -I/home/simon/R-2.4.1_otherinstall/install//lib/R/include 
-I/home/simon/R-2.4.1_otherinstall/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c 
util.c -o util.o
gcc -std=gnu99 -I/home/simon/R-2.4.1_otherinstall/install//lib/R/include 
-I/home/simon/R-2.4.1_otherinstall/install//lib/R/include  
-I/usr/local/include   -ansi -DUSE_TYPE_CHECKING_STRICT -fpic  -g -O2 -c 
zsockr.c -o zsockr.o
gcc -std=gnu99 -shared -L/usr/local/lib -o test.o alignment.o 
getzlibsock.o kaks.o util.o zsockr.o  


But the problem still occurs:
../../../R-2.4.1_otherinstall/install/bin/R

R version 2.4.1 (2006-12-18)
Copyright (C) 2006 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
...
 > dyn.load("test.o")
Erreur dans dyn.load(x, as.logical(local), as.logical(now)) :
        impossible de charger la biblioth?que partag?e 
'/home/simon/seqinr_in2p3/seqinr/src/test.o':
  /home/simon/seqinr_in2p3/seqinr/src/test.o: undefined symbol: 
getConnection
 >


Finally I tried as well on Windows and the function "getConnection" was 
not found at the compilation step.....

Thanks very much for any help!!

Simon


-- 
Simon Penel
Laboratoire de Biometrie et Biologie Evolutive           
Bat 711  -   CNRS UMR 5558  -    Universite Lyon 1              
43 bd du 11 novembre 1918 69622 Villeurbanne Cedex       
Tel:   04 72 43 29 04      Fax:  04 72 43 13 88
http://pbil.univ-lyon1.fr/members/penel



[Rd] getConnection is not found in R depending on the Linux flavour (RedHat or Debian) - dyn.load problems
Simon Penel