使用 Visual Studio 构建 R 包 (C API) [英] Building R packages (C API) with Visual Studio

查看:20
本文介绍了使用 Visual Studio 构建 R 包 (C API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Visual Studio 构建一个简单的 R 包,这是我的代码:

I'm trying to build a simple R package with Visual Studio, here is my code:

#include <R.h>
#include <Rinternals.h>

SEXP add(SEXP a, SEXP b) {
  SEXP result = PROTECT(allocVector(REALSXP, 1));
  REAL(result)[0] = asReal(a) + asReal(b);
  UNPROTECT(1);

  return result;
}

我安装了 R 运行时和 RTools.

I have R runtime and RTools installed.

当我尝试编译它时,出现以下链接错误:

When I try to compile it, I get the following link error:

error LNK2019: unresolved external symbol REAL referenced in function "struct SEXPREC * __cdecl add(struct SEXPREC *,struct SEXPREC *)" (?add@@YAPEAUSEXPREC@@PEAU1@0@Z)
error LNK2019: unresolved external symbol Rf_asReal referenced in function "struct SEXPREC * __cdecl add(struct SEXPREC *,struct SEXPREC *)" (?add@@YAPEAUSEXPREC@@PEAU1@0@Z)
error LNK2019: unresolved external symbol Rf_allocVector referenced in function "struct SEXPREC * __cdecl add(struct SEXPREC *,struct SEXPREC *)" (?add@@YAPEAUSEXPREC@@PEAU1@0@Z)
error LNK2019: unresolved external symbol Rf_protect referenced in function "struct SEXPREC * __cdecl add(struct SEXPREC *,struct SEXPREC *)" (?add@@YAPEAUSEXPREC@@PEAU1@0@Z)
error LNK2019: unresolved external symbol Rf_unprotect referenced in function "struct SEXPREC * __cdecl add(struct SEXPREC *,struct SEXPREC *)" (?add@@YAPEAUSEXPREC@@PEAU1@0@Z)

好吧,我想我缺少链接过程所需的一些二进制文件.问题是我不知道在哪里可以找到必要的 .lib 文件.在 R 运行时安装文件夹中,我可以找到 include 目录,但找不到任何 lib 目录.我错过了什么?

Well, I guess that i'm missing some binaries that are required for the linking process. The problem is that I have no idea where can I find the necessary .lib files. Inside the R runtime installation folder I can find the include directory, but I cannot find any lib directory. What am I missing?

谢谢!

推荐答案

请允许我引用 Rcpp 常见问题 小插图:

Allow me to quote from the Rcpp FAQ vignette:

我可以在 Visual Studio 中使用 Rcpp 吗?

Can I use Rcpp with Visual Studio ?

没有机会.

那不是因为我们卑鄙,而是因为 R 和 Visual工作室根本不相处.由于 Rcpp 是关于扩展RC++ 接口,我们受可用的约束工具链.而 R 根本就不能用 Visual Studio 编译.走如果您仍然心烦意乱,请向其供应商投诉.

And that is not because we are meanies but because R and Visual Studio simply do not get along. As Rcpp is all about extending R with C++ interfaces, we are bound by the available toolchain. And R simply does not compile with Visual Studio. Go complain to its vendor if you are still upset.

Microsoft 或多或少不遗余力地确保其操作系统和工具不符合 POSIX 标准.随着 R 在 Unix/POSIX 世界中长大,有一个你无法(轻松)弥合的鸿沟.

Microsoft more or less went out of its way to ensure what its OS and tooling were not POSIX compliant. As R grew up in a Unix / POSIX world there simply is a gap you cannot bridge (easily).

所以在 Windows 上是 gcc 的 MinGW 端口.

So on Windows the MinGW port of gcc it is.

这篇关于使用 Visual Studio 构建 R 包 (C API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆