我正在Mac OSX上开发一个R包,其中包含一些底层C/C++代码和openMP支持。 C++代码是使用Rcpp包编写的。我的全局“Makevars”文件位于~/.R/文件夹下。该文件如下所示。

CC=clang-omp
CXX=clang-omp++

PKG_CFLAGS=Wall -pedantic
PKG_CFLAGS= -fopenmp
PKG_CXXFLAGS= -fopenmp
PKG_LIBS= -fopenmp -lgomp

在这种配置下,一切正常!

但是,现在我想为它自己的编译生成特定于软件包的Makevars文件,以使该软件包具有可移植性。我尝试的只是将全局Makevars文件移动到我的R pakcage src文件夹中。但是,编译器提示找不到openMP头文件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

如您所见,编译器变为clangclang++,但未在Makevars文件中指定的名称:CC=clang-ompCXX=clang-omp++

问题1:那么,如何解决此问题并在R包中构建Makevars文件?

另一件事是,我从Writing R extensions注意到,
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有什么区别?我应该在哪种情况下使用?我试图用宏替换标志,但是仍然不能解决问题。

最佳答案

关于问题,我最喜欢的方法是从工作包中复制。例如,这是(推荐/核心)软件包mgcv的一部分:

PKG_LIBS =  $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CFLAGS)
PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)

我和Andreas在较小的winsorize包(在GitHub上)中使用了相同的代码段。

关于问题2:第一种形式较为笼统,将允许其他OpenMP实现。它使用R在配置时发现可用的东西。

关于c - 具有C/C++和openMP的R包: how to make "Makevars" file under "mypackage/src/" folder?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32974568/

10-10 17:42