我需要使用 GSL(GNU 库)通过 R 调用以下 C 代码。我遇到的问题是 C 代码的编译。 这是程序 mean.c:
#include <stdio.h>
#include <R.h>
#include <math.h>
#include <gsl/gsl_statistics.h>
void gsl(double *x, int *n)
{
double mean = gsl_stats_mean(x, 1, n);
Rprintf("mean = %f\n", mean);
}
命令> R CMD SHLIB mean.c
输出>
cygwin warning:
MS-DOS style path detected: C:/PROGRA~1/R/R-31~1.2/etc/i386/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-31~1.2/etc/i386/Makeconf
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gcc -m32 -shared -s -static-libgcc -o mean.dll tmp.def mean.o ipconfig -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-31~1.2/bin/i386 -lR
mean.o:mean.c:<.text+0x1b>: undefined references to 'gsl_stats_mean'
collect2: ld returned 1 exit status
在命令提示符中,我还给出了以下命令:
>gcc mean.c -Wall -I"C:/Program Files/GnuWin32/include/gsl" -L"C:/Program Files/GnuWin32/lib" -lgslcblas -lgsl -lm -o mean
我已经尝试了将 mean.c 放在中间和末尾的所有其他排列,但编译总是终止,给出消息“ld returned 1 exit status”。有时会给出消息“R.h” - 没有这样的文件或目录。
我还编辑了 PATH 并包含了 GnuWin32 文件夹及其组成部分。 我在朝着正确的方向前进吗? 任何帮助将不胜感激,谢谢!
--安琪
最佳答案
RcppGSL package在 included and fully-working package 中有工作示例以及一个更简单的样条示例。简而言之,您需要为 make
和编译器提供更多信息。
但正如 Martin Morgan 在评论中指出的那样,您也没有完全理解为什么要从 R 的 GSL 中调用均值函数...
关于在 Windows 上使用 GSL 运行 C 代码的编译错误通过 R 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30694753/