gpt4 book ai didi

c - 使用 Visual Studio 构建 R 包 (C API)

转载 作者:行者123 更新时间:2023-12-01 22:07:46 27 4
gpt4 key购买 nike

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

#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。

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

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 目录。我错过了什么?

谢谢!

最佳答案

请允许我引用Rcpp FAQ小插图:

Can I use Rcpp with Visual Studio ?

Not a chance.

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.

微软或多或少地竭尽全力确保其操作系统和工具不符合 POSIX 标准。由于 R 是在 Unix/POSIX 世界中成长起来的,因此存在着一个无法(轻易地)弥合的鸿沟。

所以在 Windows 上,它是 gcc 的 MinGW 端口。

关于c - 使用 Visual Studio 构建 R 包 (C API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34048938/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com