I'm trying to develop an R package (named gpuUtils) that will import C++ code that makes use of RViennaCL for GPU utilization.
I installed RViennaCL. Then, I followed Hadley's guidelines for package development and usage of C++ code, and created a C++ file with these lines:
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
#include "viennacl/ocl/backend.hpp"
using namespace Rcpp;
Then, when running devtools::document I get this error:
g++ -m64 -I/usr/include/R -DNDEBUG -I/usr/local/include -I"/home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/Rcpp/include" -I"/home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/RcppArmadillo/include" -I"/home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/RViennaCL/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 gpuUtils.cpp -o gpuUtils.o
In file included from /home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/RViennaCL/include/viennacl/ocl/backend.hpp:26:0,
from gpuUtils.cpp:3:
/home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/RViennaCL/include/viennacl/ocl/context.hpp:28:19: fatal error: CL/cl.h: No such file or directory
#include <CL/cl.h>
^
compilation terminated.
make: *** [gpuUtils.o] Error 1
OpenCL and CUDA are installed and I do see CL/cl.h in my system:
$ ls -1 /usr/local/cuda-9.0/include/CL
cl_egl.h
cl_ext.h
cl_gl_ext.h
cl_gl.h
cl.h
cl.hpp
cl_platform.h
opencl.h
and
$ ls -1 /usr/include/CL/
cl2.hpp
cl_egl.h
cl_ext.h
cl_gl_ext.h
cl_gl.h
cl.h
cl.hpp
cl_platform.h
opencl.h
Also, in my DESCRIPTION file I have these lines:
LinkingTo: Rcpp, RViennaCL (>= 1.7.1.7)
Imports: Rcpp
I guess that either -I/usr/include/ or -I/usr/local/cuda-9.0/include/ have to be included in my g++ call, but I'm not sure how to get Rstudio to do that.
Any idea?
Related
I'm trying to install biocneighbors from bioconductor. Unfortunately I recieve the following error:
* installing *source* package ‘BiocNeighbors’ ...
** libs
g++ -std=gnu++11 -I"/usr/include/R/" -DNDEBUG -I"/home/m3hdad/R/Rcpp/include" -
ric -O2 -pipe -fstack-protector-strong -fno-plt -c annoy_stubs.cpp -o annoy_stub
In file included from annoy_stubs.cpp:2:
annoy.h:13:10: fatal error: annoylib.h: No such file or directory
#include "annoylib.h"
^~~~~~~~~~~~
compilation terminated.
I do not understand if I have to provide the file for the algorithm "annoy" or it should be included in the source code.
I am using Arch linux.
That would be RcppAnnoy for which I am maintainer.
And BiocNeighbors has a LinkingTo: on it as it should.
So something is wrong/weird at your end as every LinkingTo: turns to a -I... as we see e.g. in your quote on the other LinkingTo: it has -- for Rcpp.
I am developing an R package on Mac OSX with some low level C/C++ code and openMP support. The C++ code is written using Rcpp package. My global ''Makevars'' file is placed under ~/.R/ folder. The file looks like following.
CC=clang-omp
CXX=clang-omp++
PKG_CFLAGS=Wall -pedantic
PKG_CFLAGS= -fopenmp
PKG_CXXFLAGS= -fopenmp
PKG_LIBS= -fopenmp -lgomp
Everything works great under this configuration!
However, now I want to build package-specific Makevars file for its own compilation to make the package portable. What I tried was simply move the global Makevars file into my R pakcage src folder. However, the compiler complained about that it cannot find the openMP header file omp.h:
** libs
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/bigmemory/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/BH/include" -fopenmp -fPIC -Wall -mtune=core2 -g -O2 -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:12:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.
make: *** [RcppExports.o] Error 1
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/bigmemory/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/BH/include" -fopenmp -fPIC -Wall -mtune=core2 -g -O2 -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:12:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.
make: *** [RcppExports.o] Error 1
As you can see, the compilers become clang and clang++, but not what specified in the Makevars files: CC=clang-omp and CXX=clang-omp++.
Question 1: So how could I fix this issue and build a Makevars file within the R package?
Another thing is that, I noticed from Writing R extensions that,
For example, a package with C code written for OpenMP should have in src/Makevars the lines
PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS)
Question 2: What is the difference between, for example, macro $(SHLIB_OPENMP_CFLAGS) and flag -fopenmp? which one under which circumstance should I use? I tried to replace the flags with the macros, but still cannot fix the issue.
Regarding question, my favourite approach is to copy from working packages. Here is eg the part from (recommended / Core) package mgcv:
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CFLAGS)
PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
I use the same snippet in the smaller winsorize package (on GitHub) by myself and Andreas.
Regarding question 2: The first form is more general and would allow other OpenMP implementations. It uses what R found to be useable when it was configured.
It sounds like you need the package Makevars as Dirk describes; for your local environment, have ~/.R/Makevars setting your C and C++ compilers to your OpenMP enabled versions using CC and CXX.
Your package (if destined for CRAN, and indeed any Mac R users who haven't battled to install an OpenMP version of clang) will need to work without OpenMP, so your code and compiler flags probably shouldn't assume its presence.
I was trying to install the package videoplayR from github but failed to do the same. I tried two ways:
1. Using the installation guidance mentioned in README file.It gave the following error:
> install_github("sjmgarnier/videoplayR")
Downloading github repo sjmgarnier/videoplayR#master
Error in function (type, msg, asError = TRUE) :
2. Using R CMD SHLIB etc gives the following error while running R CMD check. It is a part of the install.out file:
* installing source package ‘videoplayR’ ...
** libs
g++ -I/usr/share/R/include -DNDEBUG -I"/home/nandy/R/x86_64-pc-linux-gnu-library/3.1/Rcpp/include" -I"/home/nandy/R/x86_64-pc-linux-gnu-library/3.1/RcppArmadillo/include" pkg-config --cflags opencv Rscript -e <p>'Rcpp:::CxxFlags()' -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
g++ -I/usr/share/R/include -DNDEBUG -I"/home/nandy/R/x86_64-pc-linux-gnu-library/3.1/Rcpp/include" -I"/home/nandy/R/x86_64-pc-linux-gnu-library/3.1/RcppArmadillo/include" pkg-config --cflags opencv Rscript -e <p>'Rcpp:::CxxFlags()' -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c Video.cpp -o Video.o
Video.cpp: In member function ‘double Video::current_frame()’:
Video.cpp:42:25: error: ‘CV_CAP_PROP_POS_FRAMES’ was not declared in this scope
return(inputVideo.get(CV_CAP_PROP_POS_FRAMES));
^
Video.cpp: In member function ‘void Video::set_current_frame(int)’:
Video.cpp:46:18: error: ‘CV_CAP_PROP_POS_FRAMES’ was not declared in this scope
inputVideo.set(CV_CAP_PROP_POS_FRAMES, n);
^
Video.cpp: In member function ‘void Video::next_frame_cv()’:
Video.cpp:63:22: error: ‘CV_CAP_PROP_POS_FRAMES’ was not declared in this scope
if (inputVideo.get(CV_CAP_PROP_POS_FRAMES) == inputVideo.get(CV_CAP_PROP_FRAME_COUNT)) {
^
Video.cpp:63:64: error: ‘CV_CAP_PROP_FRAME_COUNT’ was not declared in this scope
if (inputVideo.get(CV_CAP_PROP_POS_FRAMES) == inputVideo.get(CV_CAP_PROP_FRAME_COUNT)) {
^
Video.cpp: In member function ‘void Video::get_frame_cv(int)’:
Video.cpp:76:27: error: ‘CV_CAP_PROP_FRAME_COUNT’ was not declared in this scope
if (n > inputVideo.get(CV_CAP_PROP_FRAME_COUNT)) {
^
Video.cpp:80:18: error: ‘CV_CAP_PROP_POS_FRAMES’ was not declared in this scope
inputVideo.set(CV_CAP_PROP_POS_FRAMES, n);
^
Video.cpp: In member function ‘int Video::length()’:
Video.cpp:91:25: error: ‘CV_CAP_PROP_FRAME_COUNT’ was not declared in this scope
return(inputVideo.get(CV_CAP_PROP_FRAME_COUNT));
^
I am guessing problem 2 is occurring due to version problem of OpenCV. Am I right? Is there any way out of this?
Looks similar to these 2 reported problems: https://github.com/hadley/devtools/issues/650 and https://github.com/hadley/devtools/issues/467. It seems that you need to update your system (Linux I presume) to the latest version of Curl.
I believe this is my fault. I forgot to exclude the compiled shared object videoplayR.so last time I committed changes to the GitHub repo. If you're using a different OS than mine (OSX Yosemite), it is most certainly the cause of the problem that you encountered. I fixed it and now it should compile nicely on your computer as well.
FYI I compiled and ran the package with both OpenCV 2.4.9 and 2.4.10, but it should work with any 2.4.X version of OpenCV (never tried the latest OpenCV 3.0 beta).
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
I have a problem importing the vector class to cython using
from libcpp.vector cimport vector
when I add this and try to compile the pyx file I get
python setup.py build_ext --inplace
running build_ext
skipping 'kmc_cy.c' Cython extension (up-to-date)
building 'kmc_cy' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -fPIC -I/usr/include/python2.7 -c kmc_cy.c -o build/temp.linux-x86_64-2.7/kmc_cy.o
kmc_cy.c:254:18: fatal error: vector: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Here is my setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import sys
sys.path.append("/usr/lib64/python2.7/site-packages/Cython/Includes/libcpp")
ext_modules = [Extension("kmc_cy", ["kmc_cy.pyx"])]
setup(
name = 'kmc_cy',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
)
Cheers
As std::vector is C++ code, you need to set the correct language:
ext_modules = [Extension("kmc_cy", ["kmc_cy.pyx"],language='c++')]
Then g++ should be used instead of gcc and the file name should end with .cpp or .cc.
See this answer for more details.