我正在构建一个 R 包,其描述包含:
LinkingTo: Rcpp
Run Code Online (Sandbox Code Playgroud)
该包具有相当深的 makefile 结构。我知道使用R CMD build .创建和修改变量,例如CXX11FLAGS必须通过后续生成文件层传递的变量。
我怀疑这LinkingTo也会产生这样一个变量,我必须知道并传递它。我怀疑这是因为,向下几层,我遇到了错误:
mycode.hpp:5:10: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>
Run Code Online (Sandbox Code Playgroud)
我不知道如何通知这个文件的 makefile Rcpp 在哪里。我怀疑可以使用假设的变量,但我不知道该变量的名称。任何人都可以澄清吗?
这是LinkingTo:来自我的一个较小的正在进行的包:
LinkingTo: Rcpp, RcppArmadillo
Run Code Online (Sandbox Code Playgroud)
编译时,这两个包都是通过-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)$
Run Code Online (Sandbox Code Playgroud)
不需要其他任何东西。编写 R 扩展 说:
希望在其他包中使用头文件的包需要在“DESCRIPTION”文件的“LinkingTo”字段中将它们声明为逗号分隔的列表。例如
Run Code Online (Sandbox Code Playgroud)LinkingTo: link1, link2'LinkingTo' 字段可以有在安装时检查的版本要求。
如果这些是包含源代码的 C++ 标头或在安装时完成静态链接,则在“LinkingTo”中指定包就足够了:包不需要(通常不应该)列在“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)
Run Code Online (Sandbox Code Playgroud)
这是 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)
Run Code Online (Sandbox Code Playgroud)
在可用的情况下还支持 OpenMP。这是目前推荐的形式。
我编辑了我的内容Makefile以包含以下黑魔法:
VARS_OLD := $(.VARIABLES)
$(foreach v, \
$(filter-out $(VARS_OLD) VARS_OLD,$(.VARIABLES)), \
$(info $(v) = $($(v))))
Run Code Online (Sandbox Code Playgroud)
当您运行时,这会打印出 R 传递给 make 进程的所有环境变量R CMD build .。
深入研究发现了一些非常有趣的变量:
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
Run Code Online (Sandbox Code Playgroud)
请注意,这些变量包含标志-I,因此必须与依赖这些标志的构建过程的任何部分进行通信。
通过在 makefile 之间传递这些,我能够实现编译。
| 归档时间: |
|
| 查看次数: |
1402 次 |
| 最近记录: |