matlab - Errors in linking fortran code that imports a MAT-file -
this question has answer here:
- reading data matlab files c 1 answer
i have import mat-file in fortran program. followed example file facing problems while linking. compilation happens fine.
minimal code:
#include "fintrf.h" program main use ssa use dmotifs use param implicit none ! mat-file declarations ! integer matopen, matgetdir integer matgetvariableinfo integer mp, dir, adir(100), pa integer mxgetm, mxgetn, matclose integer ndir, i, clstat character*32 names(100) !===========================! if(all(fnames(:)%fn .ne. argfun)) write(*,*) "no such motif: ",argfun write(*,*) "input format-> main <motifname>" stop else fin=fchton(argfun) y0=nm2m*analys(p,argfun) ! ==> open mat-file <== ! mp=matopen('./prms_lxr_29apr15.mat','r') if (mp .eq. 0) write(6,*) "can't open mat-file" stop end if dir = matgetdir(mp, ndir) if (dir .eq. 0) write(6,*) "can't read mat-file-directory." stop endif call mxcopyptrtoptrarray(dir, adir, ndir) 20 i=1,ndir call mxcopyptrtocharacter(adir(i), names(i), 32) 20 continue write(6,*) 'directory of mat-file:' 30 i=1,ndir write(6,*) names(i) 30 continue write(6,*) 'getting header info first array.' pa = matgetvariableinfo(mp, names(1)) write(6,*) 'retrieved ', names(1) write(6,*) ' size ', mxgetm(pa), '-by-', mxgetn(pa) call mxdestroyarray(pa) clstat=matclose(mp) end if end program main
i using gfortran 4.8.3 compiling+linking using default command:
gfortran main.f90 dmotifs.o param.o ssa.o -o main
this code compiles fine (without linking) when not include: #include "finitrf.h"
, otherwise compiler says
warning: main.f90:1: illegal preprocessor directive
i tried renaming finitrf.h
finitrf.f90
did not make difference. nonetheless during linking getting these errors:
main.f90:(.text+0x3ea): undefined reference `matopen_' main.f90:(.text+0x487): undefined reference `matgetdir_' main.f90:(.text+0x52b): undefined reference `mxcopyptrtoptrarray_' main.f90:(.text+0x583): undefined reference `mxcopyptrtocharacter_' main.f90:(.text+0x71b): undefined reference `matgetvariableinfo_' main.f90:(.text+0x804): undefined reference `mxgetm_' main.f90:(.text+0x855): undefined reference `mxgetn_' main.f90:(.text+0x89c): undefined reference `mxdestroyarray_' main.f90:(.text+0x8b0): undefined reference `matclose_' collect2: error: ld returned 1 exit status
do need makefile or add additional arguments in compile command?
edit:
i added -cpp
option , eliminates problem of illegal preprocessor directive
now when compiling paths matlab external components (where finitf.h) is, still getting same error.
gfortran main.f90 dmotifs.o param.o ssa.o -i/usr/local/matlab2008a/extern/include -l/usr/local/matlab2008a/extern/lib -cpp -o main
if provide library path /usr/local/matlab2008a/bin/glnxa64
contains other matlab libraries including libmat.so
, still same errors.
for lower case file extensions *.f90
or *.f
pre-processor typically deactivated. enable that, either rename (main) file have capital extension *.f90
or *.f
, or provide corresponding command-line option (-cpp
gfortran
, -fpp
ifort
).
assuming missing subroutines/functions declared in fintrf.h
, should solve problem.
you should additionally tell compiler link against libraries containing matlab functions.
Comments
Post a Comment