我该如何修复这个 C 代码/BLAS 错误?
我正在尝试编写使用 R 中的 BLAS lib 的 ac 函数(稍后将在 R 脚本中使用)
#include <stdio.h>
#include <R.h>
#include <R_ext/BLAS.h>
void foo(int *dimension, double *vect1, double *vect2)
{
const int dim = dimension[0];
const int incxy = 1;
//swaps two vectors
F77_NAME(dswap)(&dim,vect1,&incxy,vect2,&incxy);
}
我使用以下命令编译代码:
R CMD SHLIB foo.c
我收到错误:
foo.o:foo.c:(.text+0x41): undefined reference to `dswap_'
我缺少什么?
I'm trying to write a c function(that later will be used in R scripts) that uses BLAS lib from R
#include <stdio.h>
#include <R.h>
#include <R_ext/BLAS.h>
void foo(int *dimension, double *vect1, double *vect2)
{
const int dim = dimension[0];
const int incxy = 1;
//swaps two vectors
F77_NAME(dswap)(&dim,vect1,&incxy,vect2,&incxy);
}
I compile the code using :
R CMD SHLIB foo.c
I get the error :
foo.o:foo.c:(.text+0x41): undefined reference to `dswap_'
What am i missing ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
包含头文件与链接库不同。
我实际上对 R 一无所知,但我做了一些搜索并发现 http://cran.r-project.org/doc/manuals/R-exts.html#Creating-shared-objects 这表明您需要 BLAS_LIBS 变量 - 如果您不需要使用 makefile 看起来您只需获取命令“R CMD config BLAS_LIBS”的输出,然后将输出包含在命令行中。您也许也可以将其添加到 PKG_LIBS 变量中,但我对 R 的了解还不够确定。
编辑:
将 PKG_LIBS 变量替换为 LAPAK_LIBS。尝试使用 += 而不是 =。
Including a header file is not the same as linking a library.
I don't actually know anything about R, but I did some searching and found http://cran.r-project.org/doc/manuals/R-exts.html#Creating-shared-objects which indicates you need the BLAS_LIBS variable - if you're not using a makefile it looks like you can just get the output of the command "R CMD config BLAS_LIBS" and then include the output on the command line. You might also be able to just add it to the PKG_LIBS variable, but I don't know enough about R to be sure.
EDIT:
That replaces the PKG_LIBS variable with LAPAK_LIBS. Try it with += instead of =.
已设置文件
Makevars.win 包含
但错误仍然存在。
BINGO :添加到
的输出
as
中,现在它可以工作了。
have set file
Makevars.win to include
but error persists.
BINGO : added to
the output from
as in
and now it works.
它需要链接到提供 dswap 功能的任何内容。我猜那是在 R 库中。
It needs to be linked to whatever provides the
dswap
function. I would guess that's in the R library.它在这里工作(请忽略我的
~/.R/Makevars
选择特定的CC
和CFLAGS
;并忽略较小的空白编辑) :Ubuntu 10.10,R、gcc 等的库存包。也许您的 R 是在本地构建的静态库配置中?
It works here (and please ignore that my
~/.R/Makevars
selects a particularCC
andCFLAGS
; and also ignore minor whitespace edits):Ubuntu 10.10, stock packages for R, gcc etc. Maybe your R is locally built in a static library configuration?