LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Davide Cesari (dcesari_at_[hidden])
Date: 2007-11-16 03:44:14


Serge Van Criekingen ha scritto:
> Hello,
>
> I am trying to call a g95 fortran routine from a C(++) main file.
> Here are the 2 files:
> globalMain.c:
> #include <iostream>
> using namespace std;
> extern"C" {
> void fortfunc_(int *ii, float *ff);
> }
> int main( int argc , char* argv[] )
> {
> int ii=5;
> float ff=5.5;
> fortfunc_(&ii, &ff);
> return 0;
> }
>
> functF.f:
> subroutine fortfunc(ii,ff)
> integer ii
> real*4 ff
> write(6,100) ii, ff
> 100 format('ii=',i2,' ff=',f6.3)
> return
> end
>
> I installed (without any problem) the lam mpi with the g95 fortran compiler.
> My makefile is:
> CC=mpiCC
> FC=mpif77
>
> each:
> $(CC) -c globalMain.c
> $(FC) -c -fno-second-underscore -fno-underscoring functF.f
>
> all:
> $(CC) globalMain.o functF.o -o go
>
> As a result, "make each" runs find: no error message.
> But "make all" fails:
> mpiCC globalMain.o functF.o -o go
> functF.o: In function `fortfunc':
> functF.f:(.text+0x19): undefined reference to `_g95_get_ioparm'
> functF.f:(.text+0x20): undefined reference to `_g95_filename'
> functF.f:(.text+0x2b): undefined reference to `_g95_line'
> functF.f:(.text+0x3e): undefined reference to `_g95_ioparm'
> functF.f:(.text+0x4c): undefined reference to `_g95_ioparm'
> functF.f:(.text+0x5b): undefined reference to `_g95_ioparm'
> functF.f:(.text+0x6d): undefined reference to `_g95_ioparm'
> functF.f:(.text+0x7d): undefined reference to `_g95_st_write'
> functF.f:(.text+0x8b): undefined reference to `_g95_transfer_integer'
> functF.f:(.text+0x99): undefined reference to `_g95_transfer_real'
> functF.f:(.text+0x9e): undefined reference to `_g95_st_write_done'
> collect2: ld returned 1 exit status
> mpiCC: No such file or directory
> make: *** [all] Error 1
>

I would suggest to use gfortran rather than g95, since the former is
tightly integrated with gcc/g++ and you should have no library problems;
on most Linux distros gfortran is usually available as an additional
package of gcc, so it's straightforward to install, but older versions
may fail to compile code that g95 compiles. Notice that with gfortran
you do not need the "-fno-second-underscore" option, and if in C++ you
call the function "fortfunc_" with the "_", then "-fno-underscoring" is
not needed as well (also in g95 I suppose).
        hope this helps, Davide

-- 
__________________________________________________________
Davide Cesari	ARPA-Servizio Idro Meteorologico      __
  tel       (39) 051/525926                            ||\
  fax       (39) 051/6497501                           |||\
  e-mail    dcesari_at_[hidden]                        |||/
  www       http://www.arpa.emr.it/sim                 ---
  Address:  ARPA-SIM, Viale Silvani 6, 40122 Bologna, Italy
__________________________________________________________