title: access fortran module data from c using gfortran and gcc
body: <p>I'm trying to access module variables in a fortran code, calling it from C. I already call a subroutine, but cannot call the variables.</p>
  
  <pre><code>module myModule
  use iso_c_binding
  implicit none
  real(C_FLOAT) aa(3)
  contains
  subroutine fortranFunction() bind(C)
  
  print *,"hello world from Fortran 90"
  aa(1)=1.0;
  aa(2)=2.0;
  aa(3)=3.0;
  
  end subroutine
  
  end module
  </code></pre>
  
  <p>and the C code is</p>
  
  <pre><code>#include "stdio.h"
  
  extern void fortranfunction();
  extern float mymodule_aa_[3];
  
  int main()
  {
  printf("hello world from C\n");
  fortranfunction();
  
  printf("%f %f %f \n",aa[0],aa[1],aa[2]);
  return 0;
  }
  </code></pre>
  
  <p>I'm compiling via</p>
  
  <pre><code>gcc -c ccode.c
  gfortran -c fortrancode.f90
  gcc fortrancode.o ccode.o -lgfortran -o myprogram
  </code></pre>
  
  <p>to which the gcc responds with undefined reference to `aa'</p>