无法链接到fftw3库 [英] unable to link to fftw3 library

查看:774
本文介绍了无法链接到fftw3库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编译一个测试程序来测试fftw3(ver3.3.4).由于未随root previlidge一起安装,因此我使用的命令是:

I am compiling a test program to test the fftw3 (ver3.3.4). Since it is not installed with root previlidge the command I used is:

gcc -lm -L/home/my_name/opt/fftw-3.3.4/lib/ -I/home/my_name/opt/fftw-3.3.4/include/ fftwtest.c

库的安装位置

/home/my_name/opt/fftw-3.3.4/

我的代码是fftw3网站上的第一个教程:

My code is the 1st tutorial on fftw3's website:

#include <stdio.h>
#include <fftw3.h>
int main(){
    int n = 10;
    fftw_complex *in, *out;
    fftw_plan p;

    in = (fftw_complex*) fftw_malloc(n*sizeof(fftw_complex));
    out = (fftw_complex*) fftw_malloc(n*sizeof(fftw_complex));
    p = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE);

    fftw_execute(p); /* repeat as needed */

    fftw_destroy_plan(p);

    fftw_free(in); fftw_free(out);

    return 0;
}

当我编译程序时,它会向我返回以下错误:

when I compiled the program it returns me following errors:

/tmp/ccFsDL1n.o: In function `main':
fftwtest.c:(.text+0x1d): undefined reference to `fftw_malloc'
fftwtest.c:(.text+0x32): undefined reference to `fftw_malloc'
fftwtest.c:(.text+0x56): undefined reference to `fftw_plan_dft_1d'
fftwtest.c:(.text+0x66): undefined reference to `fftw_execute'
fftwtest.c:(.text+0x72): undefined reference to `fftw_destroy_plan'
fftwtest.c:(.text+0x7e): undefined reference to `fftw_free'
fftwtest.c:(.text+0x8a): undefined reference to `fftw_free'
collect2: ld returned 1 exit status

快速搜索意味着我没有正确链接到库,但是有趣的是它没有抱怨fftw_plan和fftw_complex的声明.实际上,如果我删除所有以"fftw_"开头的函数,仅保留声明,它将通过编译.

A quick search implies that I am not linking to the library correctly, but interestingly it does not complain about the declaration of fftw_plan and fftw_complex. In fact if I remove all functions starting with "fftw_", keeping only the declaration, it will pass the compilation.

那么我哪里出错了?链接正确吗?任何建议将不胜感激.

So where did I go wrong? Is the linking correct? Any suggestion would be appreciated.

推荐答案

您已经通过-L告诉链接器在哪里可以找到该库,但是您还没有告诉它要链接到哪个库.您可以通过在行的末尾-lm之前添加-lfftw3来实现后者.

You have told the linker where to find the library through -L, but you haven't told it which library to link to. The latter you do by adding -lfftw3 at the end of the line, before -lm.

此外,-L标志需要在fftwtest.c之后列出.

Additionally, the -L flag needs to be listed after fftwtest.c.

这篇关于无法链接到fftw3库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆