LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2011, 03:06 AM   #1
buddyamit
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Rep: Reputation: Disabled
Question problem calling fftw3 library function while using gfortran compiler. Please help.


Hi all:
This is my first post. I am unable to call some of the fftw3 library functions in a very simple fortran code. The code is as follows (the filename is trial.f):

Code:
program trial

implicit none

integer n1,n2,node
complex mat1(8,1),mat2(8,1)
n1 = 8
n2 = 1
node =0 
mat1 = (0.0,0.0)
mat2 = (0.0,0.0)

call cfftw(mat1,mat2,n1,n2,node)

contains

  subroutine cfftw(mat1,mat2,n1,n2,mode)

implicit none

!Input/Output variables:
integer, intent(in) :: n1,n2,mode
complex, intent(in) :: mat1(n1,n2)
complex, intent(out) :: mat2(n1,n2)
! Work variables:
integer dirn,flg,len,succ
integer (kind=8) plan
complex  :: fac
character (len=10) :: file_name
integer, parameter :: fftw_forward = -1
integer, parameter :: fftw_backward = +1
integer, parameter :: fftw_estimate = 0
integer, parameter :: fftw_measure = 1
integer, parameter :: fftw_use_wisdom = 64

len = n1*n2
if (mode .gt. 0) then
file_name = 'forwardfft'
dirn = fftw_forward
else
file_name = 'backwrdfft'
dirn = fftw_backward
endif
call dfftw_plan_dft_2d(plan, n1, n2, mat1, mat2, dirn, fftw_estimate)
call dfftw_execute(plan)
call dfftw_destroy_plan(plan)

!if (mode .gt. 0) then
!fac = zone / real(len,dp)
!call zscal(len,fac,mat2,1)
!endif
end subroutine cfftw

end program trial
Next I compile with the following command:

Quote:
gfortran -O3 -ffree-form /usr/local/lib/libfftw3.a -lm -o trial trial.f
And I get the following message:

Quote:
[amit@fedora fortran-scratchwork]$ gfortran -O3 -ffree-form /usr/local/lib/libfftw3.a -lm -o trial trial.f
/tmp/ccg7fBJ5.o: In function `MAIN__':
trial.f.text+0x8e): undefined reference to `dfftw_plan_dft_2d_'
trial.f.text+0x96): undefined reference to `dfftw_execute_'
trial.f.text+0x9e): undefined reference to `dfftw_destroy_plan_'
collect2: ld returned 1 exit status
The libraries are installed already in the concerned directory:

Quote:
[amit@fedora fortran-scratchwork]$ ls /usr/local/lib
libfftw3.a libfftw3.la libfftw.a libfftw.la librfftw.a librfftw.la pkgconfig
Any help will be immensely appreciated.

Thank you
-Amit

Last edited by buddyamit; 07-06-2011 at 03:30 AM.
 
Old 07-06-2011, 03:14 AM   #2
buddyamit
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Little typo in the compilation command. The command I give is

Quote:
gfortran -O3 -ffree-form -lgfortran -L/usr/local/lib/ -lfftw3 -lm -o trial trial.f
and the problem persists.

Last edited by buddyamit; 07-06-2011 at 03:28 AM.
 
Old 07-06-2011, 08:45 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2021 CentOS7.9 + 50+ other Linux OS, for test only.
Posts: 17,482

Rep: Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632
Welcome to LQ.
Quote:
undefined reference to `dfftw_plan_dft_2d_'
undefined reference to `dfftw_execute_'
undefined reference to `dfftw_destroy_plan_'
The three missing objects are present in a libfftw3.a for Fedora (and other Linux OS.)

Example :
Code:
[knudfl@localhost 1]$ readelf -s libfftw3.a | grep dfftw_plan_dft_2d
   107: 000022d0    83 FUNC    GLOBAL DEFAULT    2 dfftw_plan_dft_2d__
   109: 00002330    83 FUNC    GLOBAL DEFAULT    2 dfftw_plan_dft_2d_
Suggest : # yum install fftw-devel fftw-static

More questions ?
Please specify your Fedora version http://linuxsilo.net/docs/smart-questions_en.html


.
 
Old 07-06-2011, 09:21 AM   #4
buddyamit
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi knudfl:

Thanks. I did successfully re-install fftw-devel and fftw-static. However, the problem persists.
The readelf command also shows that the three unidentifiable functions are present in the archive file libfftw3.a located in /usr/loacal/lib/
I am using Fedora 10.

-Amit

Last edited by buddyamit; 07-06-2011 at 09:24 AM.
 
Old 07-06-2011, 12:51 PM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2021 CentOS7.9 + 50+ other Linux OS, for test only.
Posts: 17,482

Rep: Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632
Works here :

gfortran -O3 -ffree-form -lfftw3 -lm -o trial trial.f

.. Creates 'trial', 9.9 kB
The command ./trial exits with no errors. And with no output.


.
 
Old 07-08-2011, 01:07 AM   #6
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2021 CentOS7.9 + 50+ other Linux OS, for test only.
Posts: 17,482

Rep: Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632Reputation: 3632
Seems to prefer "libfftw.so".

When I remove the link libfftw3.so, it's left with "libfftw3.a",
and I get the same error :

$ gfortran -O3 -ffree-form -lfftw3 -lm -o trial trial.f

/home/knudfl/tmp/ccM2Lw90.o: In function `MAIN__':
trial.f.text+0x7e): undefined reference to `dfftw_plan_dft_2d_'
trial.f.text+0x86): undefined reference to `dfftw_execute_'
trial.f.text+0x8e): undefined reference to `dfftw_destroy_plan_'
collect2: ld returned 1 exit status
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash function calling problem arashdx Linux - Newbie 1 03-10-2009 04:42 PM
I have a compile problem related to fftw3 darkone66669 Programming 7 03-17-2008 03:04 PM
calling a function from within another function in php jayakrishnan Programming 2 06-19-2007 09:36 AM
Calling another function from a function using GTK geminigal Programming 4 07-11-2005 04:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration