问题描述
我正在开发Mac OSX上的R封装的一些低级别 C / C ++
code和的OpenMP
支持。在 C ++
code使用 RCPP
包写的。我的世界Makevars'文件被放置在〜/ .R /
文件夹中。该文件看起来像下面。
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!
不过,现在我想建立包特定的 Makevars
文件为自己编译,使包便于携带。我试过被简单地移动全球 Makevars
文件到我的řpakcage 的src
文件夹中。但是,编译器抱怨它找不到OpenMP的头文件 omp.h
:
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
正如你所看到的,编译器成了铛
和铛++
,而在<$ C指定不算什么$ C> Makevars 文件: CC =铛-OMP
和 CXX =铛 - OMP ++
问题1:所以,我怎么能解决这个问题,并建立一个 Makevars
第r包内的文件
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)
问题2:之间有什么区别,例如,宏 $(SHLIB_OPENMP_CFLAGS)
和标记 -fopenmp
?其中一个下情况,我应该使用?我试图与宏更换标志,但仍无法修复该问题。
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.
推荐答案
关于议题,我最喜欢的办法是从工作包复制。这里是如部分来自(推荐/核心)封装mgcv:
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)
我自己和Andreas用在较小的包(在GitHub上)相同的片段。
I use the same snippet in the smaller winsorize package (on GitHub) by myself and Andreas.
关于问题2:第一种形式是更普遍并允许其他OpenMP的实现。它采用什么ř发现它被配置时是可用的。
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.
这篇关于 - [R封装C / C ++和OpenMP:如何让&QUOT; Makevars&QUOT;根据&QUOT文件; mypackage的/ src目录/&QUOT;夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!