R cannot load libraries calling lapack functions - r

I'm trying to install some of the popular R packages but somehow my R does not see the lapack installation. Or rather the compiler doesn't see it, I guess, because when it checks LAPACK_LIBS it says it found it. I checked sessionInfo() and La_version() and they both point to where lapack is installed. How do I even go about solving it?
> install.packages("RcppArmadillo")
Installing package into ‘/homeUPDATES
/marcin/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/RcppArmadillo_0.10.5.0.0.tar.gz'
Content type 'application/x-gzip' length 1669395 bytes (1.6 MB)
==================================================
downloaded 1.6 MB
* installing *source* package ‘RcppArmadillo’ ...
** package ‘RcppArmadillo’ successfully unpacked and MD5 sums checked
** using staged installation
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ -std=gnu++14 accepts -g... yes
checking how to run the C++ preprocessor... g++ -std=gnu++14 -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ -std=gnu++14 accepts -g... (cached) yes
checking whether we have a suitable tempdir... /tmp
checking whether R CMD SHLIB can already compile programs using OpenMP... yes
checking LAPACK_LIBS... system LAPACK found
configure: creating ./config.status
config.status: creating inst/include/RcppArmadilloConfigGenerated.h
config.status: creating src/Makevars
** libs
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I'/home/marcin/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include' -I../inst/include -fpic -g -O2 -fdebug-prefix-map=/build/r-base-tbZjLv/r-base-4.1.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppArmadillo.cpp -o RcppArmadillo.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I'/home/marcin/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include' -I../inst/include -fpic -g -O2 -fdebug-prefix-map=/build/r-base-tbZjLv/r-base-4.1.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I'/home/marcin/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include' -I../inst/include -fpic -g -O2 -fdebug-prefix-map=/build/r-base-tbZjLv/r-base-4.1.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c fastLm.cpp -o fastLm.o
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -L/usr/local/opt/gsl/lib -lgsl -llapack -lgslcblas -o RcppArmadillo.so RcppArmadillo.o RcppExports.o fastLm.o -L/usr/local/opt/gettext/lib -L/usr/lib/R/lib -lR
installing to /home/marcin/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-RcppArmadillo/00new/RcppArmadillo/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘RcppArmadillo’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/marcin/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-RcppArmadillo/00new/RcppArmadillo/libs/RcppArmadillo.so':
/home/marcin/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-RcppArmadillo/00new/RcppArmadillo/libs/RcppArmadillo.so: undefined symbol: dgesvx_
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/marcin/R/x86_64-pc-linux-gnu-library/4.1/RcppArmadillo’
Warning in install.packages("RcppArmadillo") :
installation of package ‘RcppArmadillo’ had non-zero exit status
The downloaded source packages are in
‘/tmp/Rtmpw0yc9E/downloaded_packages’
>
UPDATE 1:
I made sure that the blas and lapack .so files have 755 permissions but it didn't help.
UPDATE 2:
The same problem occurs when I try to build from source a package that needs lapack. For example, I tried installing the GpGp package with the following Makevars
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS)
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
and it gives the same problem.

Try sudo apt-get update in terminal. Does it say something is locked? It looks to me like something else is using the depenent files and thus the process is locked. If this is the case you can either wait for the process to be done or reboot.
You can also try to install forcing no lock:
install.packages("RcppArmadillo",INSTALL_opts = '--no-lock')
You also might also try installing via remotes and the github page which will get you the latest dev version rather than the cran version:
library(remotes)
remotes::install_github("RcppCore/RcppArmadillo")

Please install openblas-dev libraries:
sudo apt -y install libopenblas-dev
The symbol dgesvx_ is not found. These are the extern C defines, that wrap to the fortran drivers. Then grepping for the symbol you'll find it here:
~> grep dgesvx_ /usr/lib/x86_64-linux-gnu/liblapack.so.3
grep: /usr/lib/x86_64-linux-gnu/liblapack.so.3: binary file matches

So eventually I figured out that the problem was my ~/.R/Makevars file. Dirk's comment under my original question made me wonder where do these extra commands come from and I found them in Makevars. I don't remember when and why I added something to it but when I reverted back to just an empty Makevars file everything worked! Thanks Dirk!

Related

Can't install nloptr package for R on CentOS 7

I am encountering the same type of problem as described in this question. However, in accordance with the answer, I have updated my R (version 4.1.3) and CMake (version 3.12.3) and I still can't seem to install the package. I am running CentOS 7.
Here is the log:
> install.packages("nloptr")
Installing package into ‘/home/userr/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/nloptr_2.0.0.tar.gz'
Content type 'application/x-gzip' length 2219414 bytes (2.1 MB)
==================================================
downloaded 2.1 MB
* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
** using staged installation
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ -std=gnu++11 accepts -g... yes
checking how to run the C++ preprocessor... g++ -std=gnu++11 -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ -std=gnu++11 accepts -g... (cached) yes
checking for pkg-config... /usr/bin/pkg-config
checking if pkg-config knows NLopt... no
using NLopt via local cmake build on x86_64
set CMAKE_BIN=/usr/local/bin/cmake
set CC=gcc -std=gnu11
set CFLAGS=-I/usr/local/include -fpic -g -O2
set CXX=g++
set CXXFLAGS=-std=gnu++11 -I/usr/local/include -fpic -g -O2
set LDFLAGS=-L/usr/local/lib
CMake Error: The source directory "/tmp/RtmpVJjt9p/R.INSTALL27cf4036808b/nloptr/src/nlopt-build" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
Error: /tmp/RtmpVJjt9p/R.INSTALL27cf4036808b/nloptr/src/nlopt-build is not a directory
CMake Error: The source directory "/tmp/RtmpVJjt9p/R.INSTALL27cf4036808b/nloptr/src/nlopt" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
cp: cannot stat 'nlopt/include/*': No such file or directory
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -std=gnu11 -I"/opt/R/4.1.3/lib/R/include" -DNDEBUG -I../inst/include -I'/home/userr/R/x86_64-pc-linux-gnu-library/4.1/testthat/include' -I/usr/local/include -fpic -g -O2 -c init_nloptr.c -o init_nloptr.o
gcc -std=gnu11 -I"/opt/R/4.1.3/lib/R/include" -DNDEBUG -I../inst/include -I'/home/userr/R/x86_64-pc-linux-gnu-library/4.1/testthat/include' -I/usr/local/include -fpic -g -O2 -c nloptr.c -o nloptr.o
g++ -std=gnu++11 -I"/opt/R/4.1.3/lib/R/include" -DNDEBUG -I../inst/include -I'/home/userr/R/x86_64-pc-linux-gnu-library/4.1/testthat/include' -I/usr/local/include -fpic -g -O2 -c test-C-API.cpp -o test-C-API.o
g++ -std=gnu++11 -I"/opt/R/4.1.3/lib/R/include" -DNDEBUG -I../inst/include -I'/home/userr/R/x86_64-pc-linux-gnu-library/4.1/testthat/include' -I/usr/local/include -fpic -g -O2 -c test-runner.cpp -o test-runner.o
g++ -std=gnu++11 -shared -L/opt/R/4.1.3/lib/R/lib -L/usr/local/lib -o nloptr.so init_nloptr.o nloptr.o test-C-API.o test-runner.o -L/opt/R/4.1.3/lib/R/lib -lRlapack -L/opt/R/4.1.3/lib/R/lib -lRblas -lgfortran -lm -lquadmath -Lnlopt/lib -lnlopt -L/opt/R/4.1.3/lib/R/lib -lR
installing to /home/userr/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-nloptr/00new/nloptr/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package ‘nloptr’
finding HTML links ... done
auglag html
bobyqa html
ccsaq html
check.derivatives html
cobyla html
crs2lm html
direct html
is.nloptr html
isres html
lbfgs html
mlsl html
mma html
neldermead html
newuoa html
nl.grad html
nl.opts html
nloptr-package html
nloptr html
nloptr.get.default.options html
nloptr.print.options html
print.nloptr html
sbplx html
slsqp html
stogo html
tnewton html
varmetric html
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘nloptr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/userr/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-nloptr/00new/nloptr/libs/nloptr.so':
libnlopt.so.0: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/userr/R/x86_64-pc-linux-gnu-library/4.1/nloptr’
Warning in install.packages :
installation of package ‘nloptr’ had non-zero exit status
The downloaded source packages are in
‘/tmp/Rtmp3kX1wu/downloaded_packages’
I don't know what could be causing the error, but my guess is that this line from the above log is the most relevant:
CMake Error: The source directory "/tmp/RtmpVJjt9p/R.INSTALL27cf4036808b/nloptr/src/nlopt-build" does not exist.
I would be thankful for all the help as I don't know much about Linux systems.

Shared .so file not found when loading R package with Rcpp component Linux systems

I apologize in advance if this question has been asked before but I haven't been able to find a suitable answer after days of searching.
I have a package that has a couple of small functions written in C++ using Rcpp (package can be found here). When trying to install this package on Linux systems (both local install and via Github Actions - Ubuntu 18.04, 20.04) the compiling procedure was successful but R cannot load the package because an .so file was not found. Mac and Windows systems work fine and there were no R CMD CHECK issues when tested on these systems.
I was wondering if there is any way to solve this issue? I was thinking of adding something in .Makevars but I don't know what to add.
Thank you so much in advance.
─ installing *source* package ‘CBEA’ ...
** using staged installation
** libs
g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I'/__w/_temp/Library/Rcpp/include' -I/usr/local/include -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -Wall -pedantic -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I'/__w/_temp/Library/Rcpp/include' -I/usr/local/include -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -Wall -pedantic -c gmeans.cpp -o gmeans.o
g++ -std=gnu++11 -shared -L/usr/local/lib/R/lib -L/usr/local/lib -o CBEA.so RcppExports.o gmeans.o -L/usr/local/lib/R/lib -lR
installing to /tmp/RtmpwFufM0/Rinst8982598ffd0c/00LOCK-CBEA/00new/CBEA/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘CBEA’ in library.dynam(lib, package, package.lib):
shared object ‘cbea.so’ not found
Error: loading failed
Execution halted
ERROR: loading failed
─ removing ‘/tmp/RtmpwFufM0/Rinst8982598ffd0c/CBEA’
Your (generated) NAMESPACE file has two entries referring to the package:
useDynLib(CBEA, .registration = TRUE)
useDynLib(cbea, .registration = TRUE)
Remove the second one (i.e. remove whereever you tell roxygen2 to add it, and you will be fine. The rror message you see and quote indicates a case issue as on Linux, cbea.so is different from CBEA.so (whereas macOS and Windows let you get away with it).

Failure to install phylosmith - unable to load shared object, undefined symbol

Setup:
R version 4.0.5 (2021-03-31) -- "Shake and Throw"
Platform: x86_64-pc-linux-gnu (64-bit)
Ubuntu 16.04
Issue:
Cannot install phylosmith package.
Command: devtools::install_github('schuyler-smith/phylosmith', lib = "/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/")
Output:
Downloading GitHub repo schuyler-smith/phylosmith#HEAD
✓ checking for file ‘/tmp/RtmpOU4qAW/remotes570e65639b36/schuyler-smith-phylosmith-2bd9c9b/DESCRIPTION’ ...
─ preparing ‘phylosmith’:
✓ checking DESCRIPTION meta-information ...
─ cleaning src
─ running ‘cleanup’
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘phylosmith_1.0.5.tar.gz’
* installing *source* package ‘phylosmith’ ...
** using staged installation
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ -std=gnu++11 accepts -g... yes
checking how to run the C++ preprocessor... g++ -std=gnu++11 -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ -std=gnu++11 accepts -g... (cached) yes
checking whether g++ version is sufficient... (5.4.0) yes
checking for macOS... not found as on Linux
checking for OpenMP... found
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I'/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include' -I'/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/RcppArmadillo/include' -I'/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/RcppProgress/include' -I../inst/include -fopenmp -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I'/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include' -I'/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/RcppArmadillo/include' -I'/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/RcppProgress/include' -I../inst/include -fopenmp -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c correlations_Rcpp.cpp -o correlations_Rcpp.o
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o phylosmith.so RcppExports.o correlations_Rcpp.o -fopenmp -DARMA_64BIT_WORD -L/usr/lib/R/lib -lR
installing to /home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-phylosmith/00new/phylosmith/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘phylosmith’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-phylosmith/00new/phylosmith/libs/phylosmith.so':
/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-phylosmith/00new/phylosmith/libs/phylosmith.so: undefined symbol: _ZN3tbb10interface58internal9task_base7destroyERNS_4taskE
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/phylosmith’
Warning message:
In i.p(...) :
installation of package ‘/tmp/RtmpOU4qAW/file570e27910aa/phylosmith_1.0.5.tar.gz’ had non-zero exit status'
Additional information: I have seen other posts with a similar issue, but different undefined symbols. I believe this error is specific to my given undefined symbol (_ZN3tbb10interface58internal9task_base7destroyERNS_4taskE) but I'm not sure what that has do to with it or how to resolve it.
I've tried changing libraries and installing it straight from the .tar.gz file. I have GDAL version 2.2.2 and I think its the only installation I have too.
I've even tried copying the finsihed folder before it finished installing, and pasting it into the library. The package folder looks complete. Then, when I run the command library(phylosmith), I get the output:
Error: package or namespace load failed for ‘phylosmith’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/phylosmith/libs/phylosmith.so':
/home/dunfield/R/x86_64-pc-linux-gnu-library/4.0/phylosmith/libs/phylosmith.so: undefined symbol: _ZN3tbb10interface58internal9task_base7destroyERNS_4taskE
I also ran the linux command beforehand as instructed:
sudo apt install libmysqlclient-dev libgdal-dev libudunits2-dev
I installed TBB with the terminal command apt install libtbb-dev and the TBB package in R devtools::install_package("jjallaire/TBB"). Neither attempt changed the error output even after restarting the Linux and RStudio.
At this point, I know its got to be something to do with the symbols that include tbb in the .so file. Any help troubleshooting would be greatly appreciated!
The author fixed it! Phylosmith should now be installable on Linux no problem. See github.com/schuyler-smith/phylosmith/issues/15 for detail.

Unable to install RPostgreSQL package in R Studio on CentOS 7

I installed PostgreSQL 9.6 with PostGIS 2.3 using one click installer of Enterprise DB available here on my CentOS 7 (x64) Linux based machine. Now I am trying to connect R Studio to Postgres. To do so, I tried to install RPostgreSQL package in R Studio but I am getting following error:
> install.packages("RPostgreSQL")
Installing package into ‘/home/jk/R/x86_64-redhat-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/RPostgreSQL_0.4-1.tar.gz'
Content type 'unknown' length 476204 bytes (465 KB)
==================================================
downloaded 465 KB
* installing *source* package ‘RPostgreSQL’ ...
** package ‘RPostgreSQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for pg_config... no
configure: checking for PostgreSQL header files
configure: Checking include /usr/include.
configure: Checking include /usr/include/pgsql.
configure: Checking include /usr/include/postgresql.
configure: Checking include /usr/local/include.
configure: Checking include /usr/local/include/pgsql.
configure: Checking include /usr/local/include/postgresql.
configure: Checking include /usr/local/pgsql/include.
configure: Checking include /usr/local/postgresql/include.
configure: Checking include /opt/include.
configure: Checking include /opt/include/pgsql.
configure: Checking include /opt/include/postgresql.
configure: Checking include /opt/local/include.
configure: Checking include /opt/local/include/postgresql.
configure: Checking include /opt/local/include/postgresql84.
configure: Checking include /sw/opt/postgresql-8.4/include.
configure: Checking include /Library/PostgresPlus/8.4SS/include.
configure: Checking include /sw/include/postgresql.
configure: Checking lib /usr/lib.
configure: Checking lib /usr/lib/pgsql.
configure: Checking lib /usr/lib/postgresql.
configure: Checking lib /usr/local/lib.
configure: Checking lib /usr/local/lib/pgsql.
configure: Checking lib /usr/local/lib/postgresql.
configure: Checking lib /usr/local/pgsql/lib.
configure: Checking lib /usr/local/postgresql/lib.
configure: Checking lib /opt/lib.
configure: Checking lib /opt/lib/pgsql.
configure: Checking lib /opt/lib/postgresql.
configure: Checking lib /opt/local/lib.
configure: Checking lib /opt/local/lib/postgresql.
configure: Checking lib /opt/local/lib/postgresql84.
configure: Checking lib /sw/opt/postgresql-8.4/lib.
configure: Checking lib /Library/PostgresPlus/8.4SS/lib.
configure: Checking lib /sw/lib.
checking for "/libpq-fe.h"... no
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-DBI.c -o RS-DBI.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-PQescape.c -o RS-PQescape.o
In file included from RS-PQescape.c:7:0:
RS-PostgreSQL.h:23:26: fatal error: libpq-fe.h: No such file or directory
# include "libpq-fe.h"
^
compilation terminated.
make: *** [RS-PQescape.o] Error 1
ERROR: compilation failed for package ‘RPostgreSQL’
* removing ‘/home/jk/R/x86_64-redhat-linux-gnu-library/3.3/RPostgreSQL’
Warning in install.packages :
installation of package ‘RPostgreSQL’ had non-zero exit status
The installation directory of PostgreSQL 9.6 is /opt/PostgreSQL/9.6/bin which doesn't seem to be in the error above. Could someone help me to resolve this error?
EDIT 1:
Thanks to the suggestion of #lavajumper, I got rid of above error. But now getting this error which shows some missing html links.
> install.packages("RPostgreSQL")
Installing package into ‘/home/jk/R/x86_64-redhat-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/RPostgreSQL_0.4-1.tar.gz'
Content type 'unknown' length 476204 bytes (465 KB)
==================================================
downloaded 465 KB
* installing *source* package ‘RPostgreSQL’ ...
** package ‘RPostgreSQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for pg_config... no
configure: checking for PostgreSQL header files
configure: Checking include /usr/include.
configure: Checking lib /usr/lib.
configure: Checking lib /usr/lib/pgsql.
configure: Checking lib /usr/lib/postgresql.
configure: Checking lib /usr/local/lib.
configure: Checking lib /usr/local/lib/pgsql.
configure: Checking lib /usr/local/lib/postgresql.
configure: Checking lib /usr/local/pgsql/lib.
configure: Checking lib /usr/local/postgresql/lib.
configure: Checking lib /opt/lib.
configure: Checking lib /opt/lib/pgsql.
configure: Checking lib /opt/lib/postgresql.
configure: Checking lib /opt/local/lib.
configure: Checking lib /opt/local/lib/postgresql.
configure: Checking lib /opt/local/lib/postgresql84.
configure: Checking lib /sw/opt/postgresql-8.4/lib.
configure: Checking lib /Library/PostgresPlus/8.4SS/lib.
configure: Checking lib /sw/lib.
checking for "/usr/include/libpq-fe.h"... yes
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/include -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-DBI.c -o RS-DBI.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/include -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-PQescape.c -o RS-PQescape.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/include -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-PostgreSQL.c -o RS-PostgreSQL.o
RS-PostgreSQL.c: In function ‘RS_PostgreSQL_createDataMappings’:
RS-PostgreSQL.c:446:5: warning: passing argument 1 of ‘Rf_protect’ from incompatible pointer type [enabled by default]
PROTECT(flds = RS_DBI_allocFields(num_fields));
^
In file included from /usr/include/R/Rdefines.h:36:0,
from S4R.h:64,
from RS-DBI.h:29,
from RS-PostgreSQL.h:25,
from RS-PostgreSQL.c:17:
/usr/include/R/Rinternals.h:1348:6: note: expected ‘SEXP’ but
argument is of type ‘struct RS_DBI_fields *’
SEXP Rf_protect(SEXP);
^
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/include -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-pgsql-copy.c -o RS-pgsql-copy.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/include -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-pgsql-getResult.c -o RS-pgsql-getResult.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/include -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-pgsql-pqexec.c -o RS-pgsql-pqexec.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/include -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RS-pgsql-pqexecparams.c -o RS-pgsql-pqexecparams.o
gcc -m64 -std=gnu99 -shared -L/usr/lib64/R/lib -Wl,-z,relro -o RPostgreSQL.so RS-DBI.o RS-PQescape.o RS-PostgreSQL.o RS-pgsql-copy.o RS-pgsql-getResult.o RS-pgsql-pqexec.o RS-pgsql-pqexecparams.o -L -lpq -L/usr/lib64/R/lib -lR
installing to /home/jk/R/x86_64-redhat-linux-gnu-library/3.3/RPostgreSQL/libs
** R
** inst
** preparing package for lazy loading
Creating a generic function for ‘format’ from package ‘base’ in package ‘RPostgreSQL’
Creating a generic function for ‘print’ from package ‘base’ in package ‘RPostgreSQL’
Creating a generic function for ‘summary’ from package ‘base’ in package ‘RPostgreSQL’
** help
*** installing help indices
converting help for package ‘RPostgreSQL’
finding HTML links ... done
PostgreSQL html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL /man/PostgreSQL.Rd:26: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQL.Rd:76: missing file link ‘dbUnloadDriver’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQL.Rd:84: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQL.Rd:89: missing file link ‘dbCommit’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQL.Rd:90: missing file link ‘dbRollback’
PostgreSQLConnection-class html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQLConnection-class.Rd:20: missing file link ‘dbCommit’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQLConnection-class.Rd:32: missing file link ‘dbRollback’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQLConnection-class.Rd:34: missing file link ‘dbWriteTable’
PostgreSQLDriver-class html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQLDriver-class.Rd:25: missing file link ‘dbUnloadDriver’
PostgreSQLObject-class html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQLObject-class.Rd:20: missing file link ‘isSQLKeyword’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQLObject-class.Rd:22: missing file link ‘SQLKeywords’
PostgreSQLResult-class html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQLResult-class.Rd:31: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/PostgreSQLResult-class.Rd:32: missing file link ‘fetch’
S4R html
dbApply-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbApply-methods.Rd:27: missing file link ‘fetch’
dbApply html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbApply.Rd:37: missing file link ‘fetch’
dbCallProc-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbCallProc-methods.Rd:31: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbCallProc-methods.Rd:32: missing file link ‘dbCommit’
dbCommit-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbCommit-methods.Rd:36: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbCommit-methods.Rd:37: missing file link ‘dbCommit’
dbConnect-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbConnect-methods.Rd:58: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbConnect-methods.Rd:59: missing file link ‘dbCommit’
dbDataType-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbDataType-methods.Rd:33: missing file link ‘isSQLKeyword’
dbDriver-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbDriver-methods.Rd:26: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbDriver-methods.Rd:44: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbDriver-methods.Rd:45: missing file link ‘dbCommit’
dbGetInfo-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbGetInfo-methods.Rd:47: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbGetInfo-methods.Rd:48: missing file link ‘dbCommit’
dbListTables-methods html
dbObjectId-class html
dbReadTable-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbReadTable-methods.Rd:119: missing file link ‘isSQLKeyword’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbReadTable-methods.Rd:124: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbReadTable-methods.Rd:125: missing file link ‘dbCommit’
dbSendQuery-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbSendQuery-methods.Rd:40: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbSendQuery-methods.Rd:41: missing file link ‘dbCommit’
dbSetDataMappings-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/dbSetDataMappings-methods.Rd:33: missing file link ‘fetch’
fetch-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/fetch-methods.Rd:46: missing file link ‘dbCommit’
isPostgresqlIdCurrent html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/isPostgresqlIdCurrent.Rd:34: missing file link ‘fetch’
make.db.names-methods html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/make.db.names-methods.Rd:69: missing file link ‘dbWriteTable’
postgresqlBuildTableDefinition html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/postgresqlBuildTableDefinition.Rd:41: missing file link ‘fetch’
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/postgresqlBuildTableDefinition.Rd:42: missing file link ‘dbCommit’
postgresqlDBApply html
Rd warning: /tmp/Rtmp15353Q/R.INSTALL161911b14876/RPostgreSQL/man/postgresqlDBApply.Rd:75: missing file link ‘fetch’
postgresqlSupport html
summary-methods html
** building package indices
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/jk/R/x86_64-redhat-linux-gnu-library /3.3/RPostgreSQL/libs/RPostgreSQL.so':
/home/jk/R/x86_64-redhat-linux-gnu-library/3.3/RPostgreSQL/libs/RPostgreSQL.so: undefined symbol: PQfmod
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/jk/R/x86_64-redhat-linux-gnu-library/3.3/RPostgreSQL’
Warning in install.packages :
installation of package ‘RPostgreSQL’ had non-zero exit status
Okay, I figured out the problem by myself. Answer given by #Manoj at this link helped me to resolve the second error. According to the mentioned link, RPostgreSQL checks for libraries in these directories only:
/usr/lib
/usr/lib/pgsql
/usr/lib/postgresql
/usr/local/lib
/usr/local/lib/pgsql
/usr/local/lib/postgresql
/usr/local/pgsql/lib
/usr/local/postgresql/lib
/opt/lib
/opt/lib/pgsql
/opt/lib/postgresql
/opt/local/lib
/opt/local/lib/postgresql
/opt/local/lib/postgresql84
/sw/opt/postgresql-8.4/lib
/Library/PostgresPlus/8.4SS/lib
/sw/lib
So as a superuser I copied library files from Postgres installation directory to /usr/lib and run the command again like this in R Studio:
install.packages('RPostgreSQL', dependencies=TRUE, repos='http://cran.rstudio.com/')
and it worked! :)
I had a similar issue (but with RPostgres, you may consider switching to that package) building a container through docker for API use : RPostgres was installed but the library couldn't load libpq.so.5, "unable to load shared object '/usr/local/lib/R/site-library/RPostgres/libs/RPostgres.so':\n libpq.so.5: cannot open shared object file: No such file or directory". Since I had already installed Postgres on my machine, I figure the problem was worked around therefore I had no such message on local ; but here's how I solved this in my dockerfile (thanks to this post), 100% verified on a machine with nothing related to R installed (Centos, server) :
RUN apt-get update && apt-get install libpq5 -y before installing any package.
So executing apt-get update && apt-get install libpq5 -y on your terminal should do the trick. Light and efficient.
This error also happens on Mac sometimes, and on that platform, one option is to NOT install this from source and instead pull a binary.
You can do this via specifying a type in the install.packages command.
install.packages("RPostgreSQL", type="mac.binary")
here you can find a list of other type vals
Possible values of type are (currently) "source", "mac.binary", "mac.binary.el-capitan" and "win.binary": the appropriate binary type where supported can also be selected as "binary".

R :: override C compiler using Makevars

Our R installation define in:
R$HOME/etc/Makeconf that CC = gcc -std=gnu99
I have one specific package (mix of C++ and C code) that need to be compiled using
CC = gcc
without -std=gnu99
As far as I understood I have 3 ways of doing that:
1) system wide, edit R$HOME/etc/Makeconf
2) per user basis, play with ~/.R/Makevars
3) per package basis, set PACKAGE/src/Makevars
Even if 1 and 2 is not what I want I tested the 3 options, using 1 and 2
R CMD INSTALL -l pack.tgz is OK "gcc -std=gnu99" is corectly replaced by "gcc"
But when using PACKAGE/src/Makevars approach it fails
I must admit that I'm lost at this point, where should I look ?
edit.
this is not really a duplicate with Building R Packages using Alternate GCC
for sure I have read the previous one.is the one that pointed me to Makevars
my key concern is that PACKAGE/src/Makevars is not taken in account for CC=alternate compiler while other one are working prefectly.
I had a similar problem in fortran. Anyway I made a model of your package and I found an half solution. It seems that not all the variables in PACKAGE/src/Makevars are considered and used. In order to make it work I used this Makevars file:
MY_PKG_LIBS =
MY_PKG_CCLAGS = -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g
all: $(SHLIB)
hello.o: hello.c
gcc $(MY_PKG_CCLAGS) -c hello.c -o hello.o $(MY_PKG_LIBS)
PKG_LIB = -std=gnu++11
Obviously the hello.c file should be replaced by your_file_name.c. If you can not change the CC and you adopt my workaround, the real problem become that when the shared file .so is created, the compiler flags should be overwritten using PKG_CFLAGS or PKG_CPPFLAGS as stated in Writing R Extensions (again in the Makevars file). In my personal situation (Ubuntu 15.04, R 3.1.2), I tried those and other vars following the guidelines in /etc/R/Makeconf file:
ALL_CFLAGS = $(R_XTRA_CFLAGS) $(PKG_CFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(CFLAGS)
ALL_CPPFLAGS = $(R_XTRA_CPPFLAGS) $(PKG_CPPFLAGS) $(CPPFLAGS) $(CLINK_CPPFLAGS)
The only thing that worked in adding a flag to the -shared final compiling of the package was adding the library linker flag (As I did originally with my fortran code) PKG_LIB = -std=gnu++11 in the PACKAGE/src/Makevars.
My final result in installing the package is:
Installing package into ‘/home/home/R/x86_64-pc-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘question1’ ...
** libs
gcc -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c hello.c -o hello.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o question1.so hello.o -std=gnu++11 -L/usr/lib/R/lib -lR
installing to /home/dgarolini/R/x86_64-pc-linux-gnu-library/3.1/question1/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (question1)

Resources