1

I am getting very strange error whenever I am trying to compile a C++ program with FFTW3 implementation.

I am compiling as follows

g++ -O3 -lm -lfftw3 myFile.cpp -o myFileFFTW

I also included my headers file as follows

#include <math.h> #include "fftw3.h"

The error is as follows

(.text+0x63): undefined reference to `fftw_malloc'

Any suggestions?

Edit:

the suggestion by hmjd worked for me. Linker errors when compiling against glib...?

I guess one should not work for straight 3 days otherwise mind does not work!! Special thanks hmjd!! you saved my day and I could finish my project on time !!

Community
  • 1
  • 1
VishalYadav
  • 21
  • 2
  • 5
  • 3
    Libraries at the end: `g++ -O3 myFile.cpp -o myFileFFTW -lm -lfftw3 ` See http://stackoverflow.com/questions/9966959/linker-errors-when-compiling-against-glib/9966989#9966989 – hmjd Feb 26 '13 at 14:45
  • For anyone who read this but didn't understand what the solution was, the answer is to put the linker flags at the end of the compile command, as hmjd showed but did not explain. – FreelanceConsultant Jul 19 '14 at 17:10

1 Answers1

0

I guess problem is -lfftw3 not present on your system and you are also not specifying libs correctly.

Libraries at the end of the compiler command:

gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include re.c -o re -lglib-2.0

From GCC Link Options:

-llibrary -l library Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

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.

snnippet from Linker errors when compiling against glib...?

Community
  • 1
  • 1
Saqlain
  • 17,490
  • 4
  • 27
  • 33