I am trying to execute a simple FFT using FFTW 3.3.5 over the cluster.
fftwf_plan plan = fftwf_plan_dft_1d(N, idata, odata, FFTW_FORWARD, FFTW_ESTIMATE);
//--------------------Perform FFT--------------------------
fftwf_execute(plan);
//-------------------Inverse FFT--------------------------
plan = fftwf_plan_dft_1d(N, odata, odata, FFTW_BACKWARD, FFTW_ESTIMATE);
fftwf_execute(plan);
fftwf_destroy_plan(plan);
I have tried using the following commands to execute the above code.
gcc -o fftw.out /cm/extra/apps/FFTW/3.3.5/GCC-4.9.3_MVAPICH2-2.2-GDR/lib/libfftw3.a -lm fftwCPU.c
gcc -o fftw.out -lfftw3 -lm fftwCPU.c -L/cm/extra/apps/FFTW/3.3.5/GCC-4.9.3_MVAPICH2-2.2-GDR/lib/
The path is also loaded in the LD_LIBRARY_PATH
environment variable.
GCC is able to find the path correctly but it is not linking the library. I am getting an undefined references error to all the functions of fftw.
In the above code, I have also used the fftw_ functions instead of fftwf_ functions.
More importantly, This exact code is running without any problems on my local system.
Am I doing something incorrectly?
Your option order is not correct: put the -l
options last, like so:
$ gcc -o fftw.out fftwCPU.c -L/cm/extra/apps/FFTW/3.3.5/GCC-4.9.3_MVAPICH2-2.2-GDR/lib/ -lfftw3 -lm
This is also logical; you should specify the paths before specifying which libraries to load from those paths.
From the fine manual:
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.