Error in R CMD SHLIB compiling Fortran code - r

I'm trying to compile a Fortran subroutine in the remote machine, when I run:
R CMD SHLIB -fPIC vintp2p_afterburner_wind.f
I get the following error:
gcc -shared -L/sw/installed/R/3.6.2-fosscuda-2019b/lib64/R/lib -L/sw/installed/pocl/1.4-GCC-8.3.0/lib64 -L/sw/installed/ImageMagick/7.0.9-5-GCCcore-8.3.0/lib -L/sw/installed/GSL/2.6-GCC-8.3.0/lib -L/sw/installed/UDUNITS/2.2.26-GCCcore-8.3.0/lib -L/sw/installed/HDF5/1.10.5-gompic-2019b/lib -L/sw/installed/ICU/64.2-GCCcore-8.3.0/lib -L/sw/installed/libsndfile/1.0.28-GCCcore-8.3.0/lib -L/sw/installed/FFTW/3.3.8-gompic-2019b/lib -L/sw/installed/NLopt/2.6.1-GCCcore-8.3.0/lib64 -L/sw/installed/GMP/6.1.2-GCCcore-8.3.0/lib -L/sw/installed/libxml2/2.9.9-GCCcore-8.3.0/lib -L/sw/installed/cURL/7.66.0-GCCcore-8.3.0/lib -L/sw/installed/Tk/8.6.9-GCCcore-8.3.0/lib -L/sw/installed/Java/11.0.2/lib -L/sw/installed/LibTIFF/4.0.10-GCCcore-8.3.0/lib -L/sw/installed/libjpeg-turbo/2.0.3-GCCcore-8.3.0/lib64 -L/sw/installed/libpng/1.6.37-GCCcore-8.3.0/lib -L/sw/installed/PCRE/8.43-GCCcore-8.3.0/lib -L/sw/installed/SQLite/3.29.0-GCCcore-8.3.0/lib -L/sw/installed/zlib/1.2.11-GCCcore-8.3.0/lib -L/sw/installed/XZ/5.2.4-GCCcore-8.3.0/lib -L/sw/installed/bzip2/1.0.8-GCCcore-8.3.0/lib -L/sw/installed/ncurses/6.1-GCCcore-8.3.0/lib -L/sw/installed/libreadline/8.0-GCCcore-8.3.0/lib -L/sw/installed/cairo/1.16.0-GCCcore-8.3.0/lib -L/sw/installed/libGLU/9.0.1-GCCcore-8.3.0/lib -L/sw/installed/Mesa/19.1.7-GCCcore-8.3.0/lib -L/sw/installed/X11/20190717-GCCcore-8.3.0/lib -L/sw/installed/ScaLAPACK/2.0.2-gompic-2019b/lib -L/sw/installed/OpenBLAS/0.3.7-GCC-8.3.0/lib -L/sw/installed/GCCcore/8.3.0/lib64 -L/sw/installed/GCCcore/8.3.0/lib -L/sw/installed/CUDA/10.1.243/lib64 -o vintp2p_afterburner_wind.so vintp2p_afterburner_wind.o -fPIC -lgfortran -L/sw/installed/R/3.6.2-fosscuda-2019b/lib64/R/lib -lR
/sw/installed/binutils/2.28-GCCcore-6.4.0/bin/ld.gold: error: vintp2p_afterburner_wind.o: requires dynamic R_X86_64_PC32 reloc against 'log' which may overflow at runtime; recompile with -fPIC
collect2: error: ld returned 1 exit status
make: *** [vintp2p_afterburner_wind.so] Error 1
The subroutine has a log() function. I'm totally new to this error and I don't know where to start with!

Maybe someone will find it useful: compiling is done by :
gfortran -fPIC -shared -ffree-form vintp2p_afterburner_wind.f -o vintp2p_afterburner_wind.so

Related

R package 'RcppArmadillo' error during installation

I'm trying to install RcppArmadillo in my R environment.
I have created a Docker container starting from a Ubuntu:20.04 image and installing miniconda to manage the environment and install R.
When I install RcppArmadillo I have this error:
checking whether the C++ compiler works... no
configure: error: in `/tmp/Rtmp1znFrE/R.INSTALL3901267e6e22/RcppArmadillo':
configure: error: C++ compiler cannot create executables
I have checked the config.log file to search the error, and I found this:
gcc version 9.4.0 (conda-forge 9.4.0-15)
configure:1931: $? = 0
configure:1920: aarch64-conda-linux-gnu-c++ -std=gnu++14 -V >&5
aarch64-conda-linux-gnu-c++: error: unrecognized command line option '-V'
aarch64-conda-linux-gnu-c++: fatal error: no input files
compilation terminated.
configure:1931: $? = 1
configure:1920: aarch64-conda-linux-gnu-c++ -std=gnu++14 -qversion >&5
aarch64-conda-linux-gnu-c++: error: unrecognized command line option '-qversion'; did you mean '--version'?
aarch64-conda-linux-gnu-c++: fatal error: no input files
compilation terminated.
configure:1931: $? = 1
configure:1951: checking whether the C++ compiler works
configure:1973: aarch64-conda-linux-gnu-c++ -std=gnu++14 -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -pipe -isystem /root/miniconda3/include -fdebug-prefix-map=/drone/src/build_artifacts/r-base-split_1630154255557/work=/usr/local/src/conda/r-base-4.1.1 -fdebug-prefix-map=/root/miniconda3=/usr/local/src/conda-prefix conftest.cpp >&5
/root/miniconda3/bin/../lib/gcc/aarch64-conda-linux-gnu/9.4.0/../../../../aarch64-conda-linux-gnu/bin/ld: /root/miniconda3/bin/../lib/gcc/aarch64-conda-linux-gnu/9.4.0/libstdc++.so: undefined reference to `__cxa_thread_atexit_impl#GLIBC_2.18'
collect2: error: ld returned 1 exit status
I don't understand if it's a problem of GCC (I have tried to uninstall and install again through apt-get but nothing changed), but seems really strange to me.
If I echo $PATH I get as result /root/miniconda3/bin:/usr/bin:/bin, but If I find / -name gcc I get:
/root/miniconda3/lib/R/library/BH/include/boost/mpl/aux_/preprocessed/gcc
/root/miniconda3/lib/gcc
/root/miniconda3/libexec/gcc
/root/miniconda3/libexec/gcc/aarch64-conda-linux-gnu/9.4.0/gcc
/root/miniconda3/share/licenses/gcc
/root/miniconda3/pkgs/gcc_impl_linux-aarch64-9.4.0-h603953f_15/libexec/gcc
/root/miniconda3/pkgs/gcc_impl_linux-aarch64-9.4.0-h603953f_15/libexec/gcc/aarch64-conda-linux-gnu/9.4.0/gcc
/root/miniconda3/pkgs/gcc_impl_linux-aarch64-9.4.0-h603953f_15/share/licenses/gcc
/root/miniconda3/pkgs/gcc_impl_linux-aarch64-9.4.0-h603953f_15/lib/gcc
/root/miniconda3/pkgs/libgcc-devel_linux-aarch64-9.4.0-h85f5abf_15/lib/gcc
/root/miniconda3/pkgs/libstdcxx-devel_linux-aarch64-9.4.0-h85f5abf_15/lib/gcc
/root/miniconda3/pkgs/gfortran_impl_linux-aarch64-9.4.0-h54cdb55_15/libexec/gcc
/root/miniconda3/pkgs/gfortran_impl_linux-aarch64-9.4.0-h54cdb55_15/lib/gcc
/root/miniconda3/pkgs/gxx_impl_linux-aarch64-9.4.0-h603953f_15/libexec/gcc
/usr/share/gcc
/usr/share/doc/gcc
/usr/share/doc/gcc-9-base/gcc
/usr/lib/gcc
/usr/bin/gcc
so maybe there are some mistakes in all these GCC instances.
Thanks for your help

How can I solve the CPLEX directory issues in R

The problem is that, am trying to install a package cplexAPI using the code
install.packages("cplexAPI")
"C:/rtools40/mingw32/bin/"gcc -I"C:/PROGRA~1/R/R-40~1.5/include" -DNDEBUG -g -D_R_=1 -DUSE_R=1 -I"\cplex\include" -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c cplexAPI.c -o cplexAPI.o
In file included from cplexAPI.h:26,
from cplexAPI.c:26:
cplexR.h:50:10: fatal error: ilcplex/cplex.h: No such file or directory
#include <ilcplex/cplex.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [C:/PROGRA~1/R/R-40~1.5/etc/i386/Makeconf:222: cplexAPI.o] Error 1
ERROR: compilation failed for package 'cplexAPI'
* removing 'C:/Users/ATM/Documents/R/win-library/4.0/cplexAPI'
Warning in install.packages :
installation of package ‘cplexAPI’ had non-zero exit status
What have done
Have installed IBM ILOG CPLEX Optimization Studio
Version: 12.10.0.0
and tried to install the package again and i experience the same issue
Kindly assist

R CMD SHLIB Fortran 90 file which use NetCDF

I would like compile a fortran 90 file which use NetCDF. I have installed NetCDF-Fortran and as shown here, to compile the file test_nc.f90:
program test_nc
use netcdf
implicit none
integer :: ncid, nc_err
nc_err = nf90_open('test.nc', nf90_nowrite, ncid)
nc_err = nf90_close(ncid)
end program test_nc
The compilation with gfortran is
gfortran test_nc.f90 -o test_nc `nf-config --fflags --flibs`
where nf-config --fflags --flibs is:
-I/usr/include
-L/usr/lib -lnetcdff -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -lnetcdf -lnetcdf -ldl -lz -lcurl -lm
Replacing program by subroutine is
subroutine test_nc
use netcdf
implicit none
integer :: ncid, nc_err
nc_err = nf90_open('test.nc', nf90_nowrite, ncid)
nc_err = nf90_close(ncid)
end subroutine test_nc
However, When I run
R CMD SHLIB test_nc.f90 `nf-config --fflags --flibs`
results in:
gfortran -fno-optimize-sibling-calls -fpic -g -O2 -fdebug-prefix-map=/build/r-base-k1TtL4/r-base-3.6.1=. -fstack-protector-strong -c test_nc.f90 -o test_nc.o
test_nc.f90:2:8:
2 | use netcdf
| 1
Fatal Error: Cannot open module file ‘netcdf.mod’ for reading at (1): No such file or directory
compilation terminated.
Also, when I try:
R CMD SHLIB test_nc.f90 -I/usr/include -L/usr/lib -lnetcdff -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -lnetcdf -lnetcdf -ldl -lz -lcurl -lm
gfortran -fno-optimize-sibling-calls -fpic -g -O2 -fdebug-prefix-map=/build/r-base-k1TtL4/r-base-3.6.1=. -fstack-protector-strong -c test_nc.f90 -o test_nc.o
results in:
test_nc.f90:2:8:
2 | use netcdf
| 1
Fatal Error: Cannot open module file ‘netcdf.mod’ for reading at (1): No such file or directory
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:195: test_nc.o] Error 1
How can I tell R CMD SHLIB to use the Netcdf-fortran libraries?
?SHLIB shows
R CMD SHLIB -o mylib.so a.f b.f -L/opt/acml3.5.0/gnu64/lib -lacml
So I guess it is possible to do this
In the call to R CMD SHLIB the options you have provided from nf-config are taken only as linker options. The compilation step is failing because setting the search path for the NetCDF Fortran module is required before the link process.
To add the -I... option from nf-config you can use the environment variable PKG_FCFLAGS:
env PKG_FCFLAGS="`nf-config --fflags`" R CMD SHLIB test_nc.f90 `nf-config --flibs`
Alternatively, you can put PKG_FCFLAGS in your Makevars file.
(Note that, unlike C and C++, the include path option for module files is not for the pre-processing stage.)

Compile a Rcpp package with line information in the debugging symbols

I can’t figure out how to give my R package’s shared library’s debug symbols source line information. What am I missing?
I create the following src/Makevars file:
PKG_CXXFLAGS=-O0 -ggdb
PKG_LIBS=-O0 -ggdb
I compile the package using R CMD INSTALL --no-multiarch --with-keep.source:
* installing to library ‘~/.local/lib/R/3.6’
* installing *source* package ‘reticulate’ ...
** using staged installation
g++ -std=gnu++11 -I"/usr/include/R/" -DNDEBUG -I"$HOME/.local/lib/R/3.6/Rcpp/include" -D_FORTIFY_SOURCE=2 -O0 -ggdb -fpic -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -c RcppExports.cpp -o RcppExports.o
** libs
g++ -std=gnu++11 -shared -L/usr/lib64/R/lib -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o reticulate.so RcppExports.o event_loop.o libpython.o output.o python.o readline.o -O0 -ggdb -L/usr/lib64/R/lib -lR
installing to ~/.local/lib/R/3.6/00LOCK-reticulate/00new/reticulate/libs
I debug like this:
R -d gdb --slave -e 'reticulate::py_eval("print")()'
GNU gdb (GDB) 8.3
[...]
(No debugging symbols found in /usr/lib64/R/bin/exec/R)
(gdb) break py_get_formals
Function "py_get_formals" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (py_get_formals) pending.
(gdb) run
Starting program: /usr/lib/R/bin/exec/R --slave -e reticulate::py_eval\(\"print\"\)\(\)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[...]
Thread 1 "R" hit Breakpoint 1, 0x00007fffeb6b79a0 in py_get_formals(PyObjectRef, bool) () from /home/angerer/.local/lib/R/3.6/reticulate/libs/reticulate.so
(gdb) step
Single stepping until exit from function _Z14py_get_formals11PyObjectRefb,
which has no line number information.
[...]
Why does my function not have line numbers even though I specified -ggdb in both compilation? I see that only RcppExports.cpp is mentioned in the command line, is that the problem? If so, how can I change this?
Changing the Makevars doesn’t prompt recompilation.
I needed to rm -f src/*.o src/*.so before the object files get recompiled.
This is specifically for Windows. The simplest way to do it is to set the R_MAKEVARS_USER environment to point to the Makevars.win file. That seems to work. However, debug break points have stopped working!!!!

R-3.1.3 installation from source errors .bss.zero_length_string' can not be used when making a shared object; recompile with -fPIC

I've been attempting to install R-3.1.3 from source on
# cat /etc/*release*
NAME="Amazon Linux AMI"
VERSION="2015.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2015.09"
PRETTY_NAME="Amazon Linux AMI 2015.09"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2015.09:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
Amazon Linux AMI release 2015.09
cpe:/o:amazon:linux:2015.09:ga
And after ./configure && make installation fails with the following error
gcc -std=gnu99 -shared -fopenmp -L/usr/local/lib64 -o libRlapack.so
dlamch.o dlapack.o cmplx.o -L../../../lib -lRblas -lgfortran -lm -lquadmath
/usr/bin/ld: /usr/lib/gcc/x86_64-amazon-linux/4.8.3/libgfortran.a(string_intrinsics.o): relocation R_X86_64_32S against `.bss.zero_length_string' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-amazon-linux/4.8.3/libgfortran.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[4]: *** [libRlapack.so] Error 1
Naturally I learn about -fPIC on how to recompile with -fPIC and R_X86_64_32S on What do R_X86_64_32S and R_X86_64_64 relocation mean?
I then make the change in the CFLAGS
# ./configure 'CFLAGS=-g -O2 -fPIC' --with-x=no --enable-shared
I know it worked because configure prints the values it set,
C compiler: gcc -std=gnu99 -g -O2 -fPIC
Fortran 77 compiler: gfortran -g -O2
Nevertheless same error occurs.
I've tested this on Centos65, and Centos71 and Ubuntu1404 all work, but my VPC won't, please help

Resources