【发布时间】:2016-01-28 19:00:29
【问题描述】:
我希望有人可以提供帮助。我是 C 新手,我一直在尝试 R 项目中的一些代码。我创建的项目由一个 main.c 文件和几个头文件组成。 main.c 文件如下所示:
#include "Rinternals.h"
int main(int argc, char** argv) {
}
SEXP Cdqrls(SEXP x, SEXP y, SEXP tol, SEXP chk)
{
SEXP ans;
SEXP qr, coefficients, residuals, effects, pivot, qraux;
int n, ny = 0, p, rank, nprotect = 4, pivoted = 0;
double rtol = asReal(tol), *work;
}
Rinternals.h 文件是来自 R 项目源的此文件:https://svn.r-project.org/R/trunk/src/include/Rinternals.h
我已将此头文件包含在与 main.c 文件相同的文件夹中,并且我还将 Rinternals.h #includes 语句中的所有头文件包含在此文件夹中。当我尝试编译它时,我收到以下错误:
||=== Build: Debug in MyNewProject (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `Cdqrls':|
main.c|30|undefined reference to `Rf_asReal'|
我尝试了很多方法,但似乎无法找到编译此代码的方法。我目前正在使用 Code::Blocks 并使用 GNU GCC Compiler 进行编译。对此的任何帮助将不胜感激。
【问题讨论】:
-
你记得链接到 R 吗?仅仅包含头文件不足以让编译器与库链接。
-
您确定要使用 C,而不是 C++,并且您确定要使用 SEXP,而不是 Rcpp(容易得多)吗?以及如何从控制台编译它?因为最好的方法是创建一个 R 包,在 RStudio 中加载它并单击 Build & Reload。