Pierre Lindenbaum
2024-Feb-20 09:33 UTC
[Rd] Compiling libR as a standalone C library for java+jni (-fPIC)
(cross-posted on SO: https://stackoverflow.com/questions/78022766)
Hi all,
I'm trying to compile R as a static library with the -fPIC flag so I can use
it within java+JNI (is it only possible ?), but I cannot find the right flags in
'.configure' to compile R this way.
I tested various flags but I cannot find the correct syntax.
for now, my latest attempt was
```
rm -rvf? "TMP/R-4.3.2" TMP/tmp.tar.gz
mkdir -p TMP/R-4.3.2/lib/
wget -O TMP/tmp.tar.gz
"https://pbil.univ-lyon1.fr/CRAN/src/base/R-4/R-4.3.2.tar.gz"
cd TMP && tar xfz tmp.tar.gz && rm tmp.tar.gz &&? cd
R-4.3.2 && \
??? CPICFLAGS=fpic FPICFLAGS=fpic CXXPICFLAGS=fpic SHLIB_LDFLAGS=shared?
SHLIB_CXXLDFLAGS=shared? ./configure --enable-R-static-lib --prefix=/path/to/TMP
--with-x=no --disable-BLAS-shlib && make
```
witch gives the following error during configure:
```
configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages
make[1]: Entering directory 'R-4.3.2'
configure.ac:278: error: possibly undefined macro: AM_CONDITIONAL
????? If this token and others are legitimate, please use m4_pattern_allow.
????? See the Autoconf documentation.
configure.ac:870: error: possibly undefined macro: AC_DISABLE_STATIC
configure.ac:2226: error: possibly undefined macro: AM_LANGINFO_CODESET
configure.ac:2876: error: possibly undefined macro: AM_NLS
configure.ac:2880: error: possibly undefined macro: AM_GNU_GETTEXT_VERSION
configure.ac:2881: error: possibly undefined macro: AM_GNU_GETTEXT
make[1]: *** [Makefile:49: configure] Error 1
```
removing the XXXFLAGS=YYY and --prefix (?) allows R to be compiled but It's
not loaded into java.
```
gcc? -ITMP -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/linux \
??? -LTMP/R-4.3.2/lib `TMP/R-4.3.2/bin/R CMD config --cppflags` -shared -fPIC
-o TMP/libRSession.so? -g RSession.c TMP/R-4.3.2/lib/libR.a
/usr/bin/ld: TMP/R-4.3.2/lib/libR.a(objects.o): warning: relocation against
`R_dot_Method' in read-only section `.text'
/usr/bin/ld: TMP/R-4.3.2/lib/libR.a(altrep.o): relocation R_X86_64_PC32 against
symbol `R_NilValue' can not be used when making a shared object; recompile
with -fPIC
/usr/bin/ld: final link failed: bad value
```
Any idea ? Thanks
Pierre
Dirk Eddelbuettel
2024-Feb-20 13:12 UTC
[Rd] Compiling libR as a standalone C library for java+jni (-fPIC)
Salut Pierre,
On 20 February 2024 at 10:33, Pierre Lindenbaum wrote:
| (cross-posted on SO: https://stackoverflow.com/questions/78022766)
|
| Hi all,
|
| I'm trying to compile R as a static library with the -fPIC flag so I can
use it within java+JNI (is it only possible ?), but I cannot find the right
flags in '.configure' to compile R this way.
|
| I tested various flags but I cannot find the correct syntax.
|
| for now, my latest attempt was
|
| ```
| rm -rvf? "TMP/R-4.3.2" TMP/tmp.tar.gz
| mkdir -p TMP/R-4.3.2/lib/
| wget -O TMP/tmp.tar.gz
"https://pbil.univ-lyon1.fr/CRAN/src/base/R-4/R-4.3.2.tar.gz"
| cd TMP && tar xfz tmp.tar.gz && rm tmp.tar.gz &&? cd
R-4.3.2 && \
| ??? CPICFLAGS=fpic FPICFLAGS=fpic CXXPICFLAGS=fpic SHLIB_LDFLAGS=shared?
SHLIB_CXXLDFLAGS=shared? ./configure --enable-R-static-lib --prefix=/path/to/TMP
--with-x=no --disable-BLAS-shlib && make
|
| ```
Looks like you consistenly dropped the '-' from '-fPIC'.
FWIW the Debian (and hence Ubuntu and other derivatives) binaries contain a
libR you can embed. And littler and RInside have done so for maybe 15 years.
Cannot help with JNI but note that the history of the headless (and generally
excellent) Rserve (and its clients) started on Java. Might be worth a try.
Good luck, Dirk
| witch gives the following error during configure:
|
|
| ```
| configure: WARNING: you cannot build info or HTML versions of the R manuals
| configure: WARNING: you cannot build PDF versions of the R manuals
| configure: WARNING: you cannot build PDF versions of vignettes and help pages
| make[1]: Entering directory 'R-4.3.2'
| configure.ac:278: error: possibly undefined macro: AM_CONDITIONAL
| ????? If this token and others are legitimate, please use m4_pattern_allow.
| ????? See the Autoconf documentation.
| configure.ac:870: error: possibly undefined macro: AC_DISABLE_STATIC
| configure.ac:2226: error: possibly undefined macro: AM_LANGINFO_CODESET
| configure.ac:2876: error: possibly undefined macro: AM_NLS
| configure.ac:2880: error: possibly undefined macro: AM_GNU_GETTEXT_VERSION
| configure.ac:2881: error: possibly undefined macro: AM_GNU_GETTEXT
| make[1]: *** [Makefile:49: configure] Error 1
|
| ```
| removing the XXXFLAGS=YYY and --prefix (?) allows R to be compiled but
It's not loaded into java.
|
| ```
| gcc? -ITMP -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/linux \
| ??? -LTMP/R-4.3.2/lib `TMP/R-4.3.2/bin/R CMD config --cppflags` -shared -fPIC
-o TMP/libRSession.so? -g RSession.c TMP/R-4.3.2/lib/libR.a
| /usr/bin/ld: TMP/R-4.3.2/lib/libR.a(objects.o): warning: relocation against
`R_dot_Method' in read-only section `.text'
| /usr/bin/ld: TMP/R-4.3.2/lib/libR.a(altrep.o): relocation R_X86_64_PC32
against symbol `R_NilValue' can not be used when making a shared object;
recompile with -fPIC
| /usr/bin/ld: final link failed: bad value
| ```
|
| Any idea ? Thanks
|
| Pierre
|
| ______________________________________________
| R-devel at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel
--
dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org