I am moving my first steps in writing and compiling C code and calling it from R. (I am also new to shared libraries...) My problem is that my C code uses a C function contained in another library (".a", not ".so" - is that the problem?). This is how I compile the file with the functions I want to call from R: cd /export/home/gpetris/ R SHLIB tryit.c cc -I/export/home/share/R/R-1.4.0/lib/R/include "-I/export/home/gpetris/C" -I/usr/local/include -I/export/home/share/include -KPIC -xO5 -dalign -xlic_lib=sunperf -c tryit.c -o tryit.o cc -G -o tryit.so tryit.o "-L/export/home/gpetris/lib/SUN/32bit -lutil -lrand" -L/usr/local/lib -L/export/home/share/lib Compilation finished at Fri Jan 18 12:45:20 So far, so good. But when I dyn.load it in R:> dyn.load("tryit.so")Error in dyn.load(x, as.logical(local), as.logical(now)) : unable to load shared library "/export/home/gpetris/tryit.so": ld.so.1: /export/home/share/R/R-1.4.0/lib/R/bin/R.bin: fatal: relocation error: file /export/home/gpetris/tryit.so: symbol dmatrix: referenced symbol not found The function dmatrix is contained in the object file nrutil.o in the library /export/home/gpetris/lib/SUN/32bit/libutil.a I was hoping that the flags given to R SHLIB could take care of that, but apparently I was wrong... What am I missing? Any help will be greatly appreciated. Thank you in advance, Giovanni -- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (501) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________] -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 18 Jan 2002, Giovanni Petris wrote:> > I am moving my first steps in writing and compiling C code and calling > it from R. (I am also new to shared libraries...) My > problem is that my C code uses a C function contained in > another library (".a", not ".so" - is that the problem?). > > This is how I compile the file with the functions I want to call from R: > > cd /export/home/gpetris/ > R SHLIB tryit.c > cc -I/export/home/share/R/R-1.4.0/lib/R/include "-I/export/home/gpetris/C" -I/usr/local/include -I/export/home/share/include -KPIC -xO5 -dalign -xlic_lib=sunperf -c tryit.c -o tryit.o > cc -G -o tryit.so tryit.o "-L/export/home/gpetris/lib/SUN/32bit -lutil -lrand" -L/usr/local/lib -L/export/home/share/lib > > Compilation finished at Fri Jan 18 12:45:20 > > So far, so good. But when I dyn.load it in R:Solaris, I presume from the flags, but *please* tell us enough background information.> > dyn.load("tryit.so") > Error in dyn.load(x, as.logical(local), as.logical(now)) : > unable to load shared library "/export/home/gpetris/tryit.so": > ld.so.1: /export/home/share/R/R-1.4.0/lib/R/bin/R.bin: fatal: relocation error: file /export/home/gpetris/tryit.so: symbol dmatrix: referenced symbol not found > > The function dmatrix is contained in the object file nrutil.o in > the library /export/home/gpetris/lib/SUN/32bit/libutil.a > I was hoping that the flags given to R SHLIB could take care of that, > but apparently I was wrong...Try nm -pg tryit.so and ldd tryit.so. The linker will use a shared version of libutil if one exists, and then you would need a -R flag. I am also not sure why you have quotes around parts of the cc lines: I think you have been quoting in Makevars when you should not be. -- 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thank you for the answer! There is something that is still not clear to me though... Thank you, Giovanni> > Solaris, I presume from the flags, but *please* tell us enough background > information. >Ooops! Yes, Solaris...> > Try nm -pg tryit.so and ldd tryit.so. The linker will use a shared > version of libutil if one exists, and then you would need a -R flag. >There is only a static version libutil.a. Do I need to create a shared version of it? (see below the output form nm and ldd)> I am also not sure why you have quotes around parts of the cc lines: I > think you have been quoting in Makevars when you should not be. >Correct...> > -- > 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 272860 (secr) > Oxford OX1 3TG, UK Fax: +44 1865 272595 > >Fri<15:07>gpetris[291]>nm -pg tryit.so tryit.so: 0000000000 U __1cG__CrunVdo_exit_code_in_range6Fpv1_v_ 0000000000 U __1cH__CimplKcplus_fini6F_v_ 0000000000 U __1cH__CimplKcplus_init6F_v_ 0000068252 D _DYNAMIC 0000068474 D _edata 0000068488 B _end 0000002587 D _etext 0000000000 U _ex_deregister 0000000000 U _ex_register 0000002436 T _fini 0000068124 D _GLOBAL_OFFSET_TABLE_ 0000002356 T _init 0000002568 D _lib_version 0000068152 D _PROCEDURE_LINKAGE_TABLE_ 0000001992 T create 0000000000 U dgemm 0000000000 U dmatrix 0000000000 U fprint 0000002120 T MatMult 0000000000 U messdoublematrix2 Fri<15:07>gpetris[292]>ldd tryit.so Fri<15:11>gpetris[293]> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thanks to Professor Brian Ripley I was able to fix the problem. The lessons are: 1) Don't use quotes in Makevars 2) If you want to use "sunperf" (Solaris) in a shared library, you need the flag -xlic_lib=sunperf in the variable PKG_LIBS Giovanni -- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (501) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________] -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._