在Rcpp Makevars中找到系统范围的库 [英] Locate system wide libraries in Rcpp Makevars
问题描述
我写了一个C ++软件包 P。它具有使用Rcpp构建的R接口程序包 RP。 P直接使用Make进行编译,但出于可移植性而切换到CMake。 CMake用于查找系统范围的库的标头(让我们将其称为HF集合)和静态库(在本文章的其余部分中称为SL)。
我想更新RP能够依赖于P的CMake演变。在C ++源码 RP / src / *。cpp
中,包括了HF元素,当然SL是静态链接的
在 RP / src / Makevars
中调用CMake的最佳方法是什么,以检索HF和SL?这里的重点不是要替换Rcpp的构建系统,而是要利用CMake的搜索功能。
目前,P(CMake版本)和RP可以在我的机器上,使用 RP / src / Makevars
中的绝对路径引用,例如:
INC_NLOPT = /usr/local/Cellar/nlopt/2.4.2_2/include
LIB_NLOPT = /usr/local/Cellar/nlopt/2.4.2_2/lib/libnlopt.a
$由于目前我们内部使用RP,因此可以预期将在要部署到的每台计算机上安装CMake,HF和SL。 解决方案解决方案是在RP中创建 CMakeFileLists.txt
文件/ src。在此文件中,使用CMake file
命令编写了包含所需库路径的 Libvar
文件。然后,使用 include
将 Libvar
包含在Makevars中。
在软件包根目录处执行一个配置文件,以确保在每次调用R之前生成 Libvar
。
I wrote a C++ package "P". It has an R interface package "RP", built using Rcpp. P used Make directly for compilation, but was switched to CMake for portability. CMake is used to find headers (let's call their collection HF) and static libraries (SL in the rest of the present post) for system wide libraries.
I want to update RP to be able to depend on the CMake evolution of P. In the C++ sources RP/src/*.cpp
, HF elements are included, and of course SL are statically linked.
What is the best way to call CMake in RP/src/Makevars
to retrieve the locations of HF and SL ? The point here is not to replace the build system of Rcpp, but to leverage the search capabilities of CMake.
At the moment, P (CMake version) and RP build on my machine, using absolute path references in RP/src/Makevars
such as:
INC_NLOPT = /usr/local/Cellar/nlopt/2.4.2_2/include
LIB_NLOPT = /usr/local/Cellar/nlopt/2.4.2_2/lib/libnlopt.a
Since we use RP internaly at the moment, we can expect CMake, HF and SL to be installed on every machine we will deploy to.
解决方案 The solution was to create a CMakeFileLists.txt
file in RP/src. In this file, a Libvar
file containing the required library paths is written using CMake file
command. Libvar
is then included in Makevars using include
.
A configure file at the root of the package is executed to ensure that Libvar
is generated before every call to make by R.
这篇关于在Rcpp Makevars中找到系统范围的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!