“LinkingTo”在R包中做了什么?

时间:2017-08-04 18:08:18

标签: r rcpp

我正在构建一个R包,其描述包含:

LinkingTo: Rcpp

该包具有相当深的makefile结构。我知道使用R CMD build .创建和修改CXX11FLAGS等变量,这些变量必须通过后续的makefile层向下传递。

我怀疑LinkingTo也产生了这样一个变量,我必须注意并传递它。我怀疑这是因为,几层下来,我点击错误:

mycode.hpp:5:10: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>

我不确定如何通知此文件的makefile以了解Rcpp的位置。我怀疑可以使用假设变量,但我不知道该变量的名称。任何人都可以澄清吗?

2 个答案:

答案 0 :(得分:4)

以下是来自我的一个较小的正在进行的包中的LinkingTo:

LinkingTo: Rcpp, RcppArmadillo

编译时,这两个包都通过-I...开关使用:

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)$ 

没有其他需要。编写R扩展名称:

  

希望在其他包中使用头文件的包   需要在字段中将它们声明为以逗号分隔的列表   'DESCRIPTION'文件中的'LinkingTo'。例如

 LinkingTo: link1, link2
     

'LinkingTo'字段可以具有检查的版本要求   在安装。

     

如果这些是C ++,在'LinkingTo'中指定包就足够了   包含源代码或静态链接的标题在   安装:包不需要(通常不应该   be)在'Depends'或'Imports'字段中列出。这包括CRAN   包 BH https://CRAN.R-project.org/package=BH)几乎全部   用户    RcppArmadillo https://CRAN.R-project.org/package=RcppArmadillo)和    RcppEigen https://CRAN.R-project.org/package=RcppEigen)。

     

对于'LinkingTo'的另一种用法,请参阅* note链接到本​​机例程   在其他包::。

,从(基本上是空的)src/Makevars

可以看出这一点
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

这是RcppArmadillo用于支持LAPACK和BLAS的外部链接的标准用法。请注意,我的软件包稍稍落后,因为RcppArmadillo在其最新版本中现在使用inst/skeleton/Makevars次传递到通过RcppArmadillo.package.skeleton()创建的每个软件包中:

## optional
#CXX_STD = CXX11

PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

还支持OpenMP(如果可用)。这是目前推荐的表格。

答案 1 :(得分:-1)

我编辑了Makefile以包含以下黑暗魔法:

VARS_OLD := $(.VARIABLES)
$(foreach v,                                        \
$(filter-out $(VARS_OLD) VARS_OLD,$(.VARIABLES)),   \
$(info $(v) = $($(v))))

当您运行R CMD build .时,这将打印出由R传递给make过程的所有环境变量。

挖掘这一点揭示了一些非常有趣的变量:

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

请注意,这些变量包含-I标志,因此必须传达给依赖于这些变量的构建过程的任何部分。

通过在makefile之间传递这些,我能够实现编译。

相关问题