Samsiddhi Bhattacharjee
2009-Jan-10 22:52 UTC
[R] Problem with compiling shared C/C++ library for loading into R (Linux)
I am using the .Call interface to call c++ code from R. For that, I am trying to create a dynamic library (mylib.so) using "R CMD SHLIB" by linking my own c++ code and an external c++ library (blitz++). The makefile works fine on my Mac, produces mylib.so and I am able to call .Call() from R, but on a linux server (I think Debian), I got the following error: ---------- /usr/bin/ld: /somepath/blitz/lib/libblitz.a(globals.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /somepath/blitz/lib/libblitz.a: could not read symbols: Bad value collect2: ld returned 1 exit status ---------- I tried recompiling the blitz++ library with the -fPIC flag, and then linking using -fPIC, it went thorugh without error producing a "mylib.so" file. But when I tried "dyn.load(mylib.so)" from R, I got the error: ---------- Error in dyn.load("mylib.so") : unable to load shared library '/somepath/mylib.so': /somepath/mylib.so: undefined symbol: _ZSt4cerr --------- I will really appreciate any help or advice on this problem. --Samsiddhi
Samsiddhi Bhattacharjee
2009-Jan-10 23:40 UTC
[R] Problem with compiling shared C/C++ library for loading into R (Linux)
Dear all, Sorry about posting this to R-help by mistake. I just realized it belongs to the r-devel list. So I am reposting it there. --------- I am using the .Call interface to call c++ code from R. For that, I am trying to create a dynamic library (mylib.so) using "R CMD SHLIB" by linking my own c++ code and an external c++ library (blitz++). The makefile works fine on my Mac, produces mylib.so and I am able to call .Call() from R, but on a linux server (I think Debian), I got the following error: ---------- /usr/bin/ld: /somepath/blitz/lib/libblitz.a(globals.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /somepath/blitz/lib/libblitz.a: could not read symbols: Bad value collect2: ld returned 1 exit status ---------- I tried recompiling the blitz++ library with the -fPIC flag, and then linking using -fPIC, it went thorugh without error producing a "mylib.so" file. But when I tried "dyn.load(mylib.so)" from R, I got the error: ---------- Error in dyn.load("mylib.so") : unable to load shared library '/somepath/mylib.so': /somepath/mylib.so: undefined symbol: _ZSt4cerr --------- I will really appreciate any help or advice on this problem. --Samsiddhi
Samsiddhi Bhattacharjee
2009-Jan-10 23:54 UTC
[Rd] Problem with compiling shared C/C++ library for loading into R (Linux)
Dear all, I am using the .Call interface to call c++ code from R. For that, I am trying to create a dynamic library (mylib.so) using "R CMD SHLIB" by linking my own c++ code and an external c++ library (blitz++). The makefile works fine on my Mac, produces mylib.so and I am able to call .Call() from R, but on a linux server (I think Debian), I got the following error: ---------- /usr/bin/ld: /somepath/blitz/lib/libblitz.a(globals.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /somepath/blitz/lib/libblitz.a: could not read symbols: Bad value collect2: ld returned 1 exit status ---------- I tried recompiling the blitz++ library with the -fPIC flag, and then linking using -fPIC, it went thorugh without error producing a "mylib.so" file. But when I tried "dyn.load(mylib.so)" from R, I got the error: ---------- Error in dyn.load("mylib.so") : unable to load shared library '/somepath/mylib.so': /somepath/mylib.so: undefined symbol: _ZSt4cerr --------- I will really appreciate any help or advice on this problem. --Samsiddhi Bhattacharjee