我该如何修复这个 C 代码/BLAS 错误?

发布于 2024-10-31 00:07:07 字数 542 浏览 5 评论 0原文

我正在尝试编写使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

野心澎湃 2024-11-07 00:07:07

包含头文件与链接库不同。

我实际上对 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 的了解还不够确定。

编辑:

已将文件 Makevars.win 设置为包含

PKG_LIBS=$(BLAS_LIBS) 
PKG_LIBS=$(LAPAK_LIBS)

将 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:

have set file Makevars.win to include

PKG_LIBS=$(BLAS_LIBS) 
PKG_LIBS=$(LAPAK_LIBS)

That replaces the PKG_LIBS variable with LAPAK_LIBS. Try it with += instead of =.

夜巴黎 2024-11-07 00:07:07

已设置文件
Makevars.win 包含

PKG_LIBS=$(BLAS_LIBS) 
PKG_LIBS=$(LAPAK_LIBS)

但错误仍然存​​在。

BINGO :添加到

"R CMD SHLIB foo.c"

的输出

"R CMD config BLAS_LIBS"

as

"R CMD SHLIB foo.c -LC:/PROGRA~1/R/R-212~1.2/bin/i386 -lRblas"

中,现在它可以工作了。

have set file
Makevars.win to include

PKG_LIBS=$(BLAS_LIBS) 
PKG_LIBS=$(LAPAK_LIBS)

but error persists.

BINGO : added to

"R CMD SHLIB foo.c"

the output from

"R CMD config BLAS_LIBS"

as in

"R CMD SHLIB foo.c -LC:/PROGRA~1/R/R-212~1.2/bin/i386 -lRblas"

and now it works.

从此见与不见 2024-11-07 00:07:07

它需要链接到提供 dswap 功能的任何内容。我猜那是在 R 库中。

It needs to be linked to whatever provides the dswap function. I would guess that's in the R library.

流星番茄 2024-11-07 00:07:07

它在这里工作(请忽略我的 ~/.R/Makevars 选择特定的 CCCFLAGS;并忽略较小的空白编辑) :

edd@max:/tmp$ R CMD SHLIB foo.c
gcc-4.5 -I/usr/share/R/include -fpic -O3 -g0 -Wall -pipe -pedantic -std=gnu99 \
        -c foo.c -o foo.o
gcc -shared -o foo.so foo.o -L/usr/lib64/R/lib -lR
edd@max:/tmp$ cat foo.c
#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);
}
edd@max:/tmp$ 

Ubuntu 10.10,R、gcc 等的库存包。也许您的 R 是在本地构建的静态库配置中?

It works here (and please ignore that my ~/.R/Makevars selects a particular CC and CFLAGS; and also ignore minor whitespace edits):

edd@max:/tmp$ R CMD SHLIB foo.c
gcc-4.5 -I/usr/share/R/include -fpic -O3 -g0 -Wall -pipe -pedantic -std=gnu99 \
        -c foo.c -o foo.o
gcc -shared -o foo.so foo.o -L/usr/lib64/R/lib -lR
edd@max:/tmp$ cat foo.c
#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);
}
edd@max:/tmp$ 

Ubuntu 10.10, stock packages for R, gcc etc. Maybe your R is locally built in a static library configuration?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文