Dyn.load unable to load object compiled with -fopenmp Rcpp - r

I am using g++ (GCC) 4.6.1 to compile my Rcpp package. However with -fopenmp option it is giving error in "dyn.load" (unable to load *.so). Without -fopenmp package INSTALL smoothly. I am using latest Rcpp . The only warning during the compilation is:
compiler_setup.hpp:169:110: note: #pragma message: Your C++ compiler is in C++11 mode, but it has incomplete support for C++11 features
.so: undefined symbol: dsyevd_
The R version is 3.0.2 Patched (2013-10-11 r64042). My other c-code that don't use Rcpp works fine with -fopenmp. The g++ run by installation is
g++ -DNDEBUG -DUSE_R -DNDEBUG -DDISABLE_SINGLE -DNTHROW -DDISABLE_FIO -I/usr/local/include -I"./3.0/Rcpp/include" -fopenmp -fpic -g -O3 -pipe -std=c++0x -Wall -pedantic -c eQTL.cpp -o eQTL.o

Related

Brew clang++ issue with cmath in OSX Catalina

Having a recurring issue with cmath upon compiling the source R package in OSX 10.15, as follows;
In file included from /usr/local/opt/llvm/bin/../include/c++/v1/complex:245:
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:313:9: error: no member named 'signbit' in the global namespace
using ::signbit;
~~^
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:314:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
~~^
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:315:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
~~^
/usr/local/include/math.h:749:12: note: 'finite' declared here
extern int finite(double)
Installation output from R shows clang++ with following arguments;
clang++ -fopenmp -std=gnu++11 -I"/usr/local/Cellar/r/3.6.2/lib/R/include" -DNDEBUG -I"/Volumes/Documents/Library/R/3.x/library/BH/include" -I"/Volumes/Documents/Library/R/3.x/library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include -fPIC -g -O3 -Wall -pipe -Wno-nonnull -pedantic -std=c++11 -mtune=native -c AlphaProcedure.cpp -o AlphaProcedure.o
I've read several similar posting having the similar issues but none of workaround has worked on my system so far. I'd really appreciate any input on this.
My system:
sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.2
BuildVersion: 19C57
xcodebuild -version
Xcode 11.3
Build version 11C29
clang -v
clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/9.2.0_3/libexec/gcc/x86_64-apple-darwin19/9.2.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/9.2.0_3 --libdir=/usr/local/Cellar/gcc/9.2.0_3/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.2.0_3' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
Thread model: posix
gcc version 9.2.0 (Homebrew GCC 9.2.0_3)
C complier flags in zshrc
CPATH=/usr/local/include
CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
LDFLAGS=-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib
Makevars (for R)
LLVM_LOC = /usr/local/opt/llvm
CC=clang -fopenmp
CXX=clang++ -foropenmp
CXX11=clang++ -fopenmp
CFLAGS = -g -O3 -Wall -pipe -pedantic -Wno-nonnull -std=gnu99 -mtune=native -pipe
CXXFLAGS = -g -O3 -Wall -pipe -Wno-nonnull -pedantic -std=c++11 -mtune=native
CXX11FLAGS = -g -O3 -Wall -pipe -Wno-nonnull -pedantic -std=c++11 -mtune=native
LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include
I took the nuclear option (clean install Catalina) and used llvm provided by Apple with Brew installation of some required apps. All of this fixed the issue. One minor fix is in Makevars with CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

Linux issue happens on Windows? "fatal error: fftw3.h: No such file or directory"

I am running MRO 3.5.0 on Win10, and trying to install a package image.CannyImage from bnosac/image on the github. But it keeps reporting fatal errors as following.
* installing *source* package 'image.CannyEdges' ...
** libs
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_64/bin/gcc -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -std=gnu99 -mtune=core2 -c adsf.c -o adsf.o
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -mtune=core2 -c rcpp_canny.cpp -o rcpp_canny.o
In file included from rcpp_canny.cpp:13:0:
canny.h:8:19: fatal error: fftw3.h: No such file or directory
#include <fftw3.h>
^
compilation terminated.
make: *** [C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/etc/x64/Makeconf:215: rcpp_canny.o] Error 1
ERROR: compilation failed for package 'image.CannyEdges'
* removing 'C:/Users/eric1/Documents/R/win-library/3.5/image.CannyEdges'
In R CMD INSTALL
Installation failed: Command failed (1)
^
compilation terminated.
Google says I can solve the issue by sudo apt-get remove libfftw3-dev. Unfortunately, I am on Windows, and some advised, apply lib /machine:i386 /def:libfftw3-3.def on cmd mode. Ouch, there is no such command or file called lib.exe on Win10.
Please advise, how I can solve this issue on my Win10+MRO system. Thanks.
Even though this question is already a bit old:
By now (Feb 2020) there are precompiled packages available that work also under Windows:
Canny Edges - Package
and more general:
List of all available packages
I have tried installing them and (at least for me) it worked.

What does `LinkingTo` do in an R package? [duplicate]

This question already has an answer here:
Do I need to import RccpEigen in the DESCRIPTION file for an R package using it, or is "LinkingTo" enough?
(1 answer)
Closed 5 years ago.
I am building an R package whose description contains:
LinkingTo: Rcpp
The package has a fairly deep makefile structure. I know using R CMD build . creates and modifies variables such as CXX11FLAGS which must be passed down through subsequent layers of makefiles.
I suspect that LinkingTo also produces such a variable, which I must be aware of and pass along. I suspect this because, several layers down, I hit the error:
mycode.hpp:5:10: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>
I'm not sure how to inform this file's makefile as to where Rcpp is. I suspect the hypothesized variable could be used, but I do not know that variable's name. Can anyone clarify?
Here is LinkingTo: from a smaller in-progress package of mine:
LinkingTo: Rcpp, RcppArmadillo
When compiling, these two packages are both uses via -I... switches:
edd#bud:~/git/rcppkalman(master)$ ./cleanup
edd#bud:~/git/rcppkalman(master)$ R CMD INSTALL .
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘RcppKalman’ ...
** libs
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -Werror -march=native -c RcppExports.cpp -o RcppExports.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -Werror -march=native -c expmMat.cpp -o expmMat.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -Werror -march=native -c kfpredict.cpp -o kfpredict.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -Werror -march=native -c kfupdate.cpp -o kfupdate.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -Werror -march=native -c ltidisc.cpp -o ltidisc.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -Werror -march=native -c rtssmooth.cpp -o rtssmooth.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -Werror -march=native -c tfsmooth.cpp -o tfsmooth.o
g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o RcppKalman.so RcppExports.o expmMat.o kfpredict.o kfupdate.o ltidisc.o rtssmooth.o tfsmooth.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/RcppKalman/libs
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (RcppKalman)
edd#bud:~/git/rcppkalman(master)$
There is nothing else needed. Writing R Extensions says:
A package that wishes to make use of header files in other packages
needs to declare them as a comma-separated list in the field
'LinkingTo' in the 'DESCRIPTION' file. For example
LinkingTo: link1, link2
The 'LinkingTo' field can have a version requirement which is checked
at installation.
Specifying a package in 'LinkingTo' suffices if these are C++
headers containing source code or static linking is done at
installation: the packages do not need to be (and usually should not
be) listed in the 'Depends' or 'Imports' fields. This includes CRAN
package BH (https://CRAN.R-project.org/package=BH) and almost all
users of
RcppArmadillo (https://CRAN.R-project.org/package=RcppArmadillo) and
RcppEigen (https://CRAN.R-project.org/package=RcppEigen).
For another use of 'LinkingTo' see *note Linking to native routines
in other packages::.
and that is on point as can be seen from the (essentially empty) src/Makevars:
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
which is the standard uses by RcppArmadillo to support the external linking for LAPACK and BLAS. Note that my package is a little behind as RcppArmadillo in its most recent release now uses this inst/skeleton/Makevars passes into every package created via RcppArmadillo.package.skeleton():
## optional
#CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
to also support OpenMP where available. That is the current recommended form.
I edited my Makefile to include the following dark magic:
VARS_OLD := $(.VARIABLES)
$(foreach v, \
$(filter-out $(VARS_OLD) VARS_OLD,$(.VARIABLES)), \
$(info $(v) = $($(v))))
This prints out all of the environmental variables passed to the make process by R when you run R CMD build ..
Digging in this revealed some very interesting variables:
ALL_CPPFLAGS = -I/usr/share/R/include -DNDEBUG -I"/home/myuser/.R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include"
CLINK_CPPFLAGS = -I"/home/myuser/.R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include"
R_INCLUDE_DIR = /usr/share/R/include
Note that these variables contain the -I flag and, thus, must be communicated to any part of the build process that relies on those.
By passing these between makefiles I was able to achieve compilation.

Compiling an adjusted package in Windows

I am trying to create a package from an existed package called "rDEA". Basically, I have adjusted and added some functions to the source .R files and the DESCRIPTION file to include Depends:. However, when I checked the package I got the following 00install.out:
* installing *source* package 'rDEA' ...
** libs
*** arch - i386
gcc -m32 -I"C:/PROGRA~1/R/R-32~1.2/include" -DNDEBUG -g -D_R_=1 -DUSE_R=1 -I/include -DCHECK_GLPK_ARGS -I"d:/RCompile/r-compiling/local/local320/include" -O3 -Wall -std=gnu99 -mtune=core2 -c multi_glp_solve.c -o multi_glp_solve.o
gcc -m32 -I"C:/PROGRA~1/R/R-32~1.2/include" -DNDEBUG -g -D_R_=1 -DUSE_R=1 -I/include -DCHECK_GLPK_ARGS -I"d:/RCompile/r-compiling/local/local320/include" -O3 -Wall -std=gnu99 -mtune=core2 -c rDEA_initialize.c -o rDEA_initialize.o
gcc -m32 -shared -s -static-libgcc -o rDEA.dll tmp.def multi_glp_solve.o rDEA_initialize.o -L/lib -lglpk -lgmp -Ld:/RCompile/r-compiling/local/local320/lib/i386 -Ld:/RCompile/r-compiling/local/local320/lib -LC:/PROGRA~1/R/R-32~1.2/bin/i386 -lR
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lglpk
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lgmp
collect2: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'rDEA'
* removing 'C:/Users/Dell/Documents/rDEA.Rcheck/rDEA'
Here, it seems that the files lglpk and lgmp are not found when compiling. They are created from Makevars.win in the src as follows:`
#-*- Makefile -*-
#
PKG_CPPFLAGS=-g -D_R_=1 -DUSE_R=1 -I${GLPK_HOME}/include -DCHECK_GLPK_ARGS
PKG_LIBS=-L${GLPK_HOME}/lib -lglpk -lgmp
My questions are: How to solve this issue? Do I need to change directory? Or do I need to use GSL (GNU Scientific Library) or other compilers? and how?
Please excuse my ignorance as I am no a computer scientist nor had good programming background.
Your help would be greatly appreciated. Many thanks!!

R Rcpp install error in R 3.1.0

I want to install Rcpp using install.packages("Rcpp"), but it failed.
The error message:
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** libs
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -I/usr/local/include -fpic -g -O2 -c Date.cpp -o Date.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -I/usr/local/include -fpic -g -O2 -c Module.cpp -o Module.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -I/usr/local/include -fpic -g -O2 -c Rcpp_init.cpp -o Rcpp_init.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -I/usr/local/include -fpic -g -O2 -c api.cpp -o api.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -I/usr/local/include -fpic -g -O2 -c attributes.cpp -o attributes.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -I/usr/local/include -fpic -g -O2 -c barrier.cpp -o barrier.o
g++ -shared -L/usr/local/lib64 -o Rcpp.so Date.o Module.o Rcpp_init.o api.o attributes.o barrier.o
installing to /home/sethbrin/R/x86_64-redhat-linux-gnu-library/3.1/Rcpp/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/sethbrin/R/x86_64-redhat-linux-gnu-library/3.1/Rcpp/libs/Rcpp.so':
/home/sethbrin/R/x86_64-redhat-linux-gnu-library/3.1/Rcpp/libs/Rcpp.so: undefined symbol: _ZNSt15basic_streambufIcSt11char_traitsIcEE7seekoffExSt12_Ios_SeekdirSt13_Ios_Openmode
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/sethbrin/R/x86_64-redhat-linux-gnu-library/3.1/Rcpp’
The downloaded source packages are in
‘/tmp/Rtmp6PKB8N/downloaded_packages’
Warning message:
In install.packages("Rcpp") :
installation of package ‘Rcpp’ had non-zero exit status
Then I use
c++fit _ZNSt15basic_streambufIcSt11char_traitsIcEE7seekoffExSt12_Ios_SeekdirSt13_Ios_Openmode
std::basic_streambuf<char, std::char_traits<char> >::seekoff(long long, std::_Ios_Seekdir, std::_Ios_Openmode)
I have searched for some solutions for that. It seems that it is because of the gcc version. But I don't know how to change the gcc version that R uses to compile Rcpp package.
CRAN tests Rcpp just like any other of the (by now) 6700+ package.
You can see the aggregate test report and the test setups includes two Fedora-based machines:
one fedora setup using clang and
one fedora setup using g++.
As such your problems are possibly local, or simply due to using an older setup. In which case the Archive section gives you access to an older version.
I've encountered a similar problem.
And after some searches, here are the solutions to alter the compiler:
1. If you have the root privilege:
I found that the Makeconf file in R directory actually sets all the information that is needed for compilation.
To find the path to it, echo which R in the command line.
e.g. I got like:
/data/apps/R/3.1.2/bin/R
And then the file is in:
/data/apps/R/3.1.2/lib64/R/etc/Makeconf
then sudo edit the file on line CC = XXX and maybe more relative lines.
Problem solved!
2. If you only have local user privilege.
Add your own configurations to ~/.R/Makevars
However, #Dirk is probably right.
For me, I finally solved my problem by adding -Doff_t=__off_t to CFLAGS (My problem was error: unknown type name 'off_t'). And I got the halted error when I manually altered parts of the compilers...

Resources