Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3433  / 2 Years ago, mon, march 28, 2022, 7:44:43

I have got below error message when I tried running a program.



undefined reference to `fftw_malloc'
f11.c:(.text+0x24d): undefined reference to `fftw_malloc'
f11.c:(.text+0x260): undefined reference to `fftw_malloc'
f11.c:(.text+0x273): undefined reference to `fftw_malloc'
f11.c:(.text+0x286): undefined reference to `fftw_malloc'


and so on.



what is the problem exactly? It is running fine with 11.04 version, please help!






i reinstalled the gcc, but problem still exist
i used a command like this: g++ -lfftw3 -lcpgplot -lpgplot f11.c.
the out puts are:
undefined reference tofftw_malloc' f11.c:(.text+0x260): undefined reference to fftw_malloc' f11.c:(.text+0x273): undefined reference tofftw_malloc' f11.c:(.text+0x286): undefined reference to `fftw_malloc



undefined reference to cpgbeg'
f11.c:(.text+0x2d3c): undefined reference to
cpgpage'
f11.c:(.text+0x2d49): undefined reference to cpgsch'
f11.c:(.text+0x2d71): undefined reference to
cpgsvp'
please give me suggestion.


More From » compiling

 Answers
4

Ok, so Ubuntu package libfftw3-dev is installed, which is obvious as you would get an error message



/usr/bin/ld: cannot find -lfftw3


instead if the library was not found by the linker.



There is a hint in the gcc linker documentation saying that the order of files given to the linker is important. Citing from the documentation




It makes a difference where in the command you write this option [-l library]; 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.




In your case, no functions referenced by f11.c are being loaded from the specified library, since they are listed before f11.c. This is somewhat counterintuitive, but I am pretty sure that compiling with



g++ f11.c -lfftw3 -lcpgplot -lpgplot


will be the solution to your problem. You may need to check the order of the libraries though, in case they depend on each other. In general, if (file or library) x depends on (file or library) y, make sure that x is listed before y on the command line given to the linker.


[#35360] Monday, March 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
inglehare

Total Points: 330
Total Questions: 111
Total Answers: 95

Location: Sint Maarten
Member since Tue, Mar 29, 2022
2 Years ago
;