title: Undefined references in libfftw3_mpi.a with gcc-5
body: <p>I am new to fftw library. I recently downloaded a simple mpi-fftw code from <a href="http://micro.stanford.edu/wiki/Install_FFTW3#Parallel_MPI" rel="nofollow noreferrer">here</a>. I have some undefined references to mpi functions from libfftw3_mpi.a when I compile the code on Ubuntu 18.04 as </p>
  
  <pre><code>mpicc -I /usr/local/include -L /usr/local/lib  simple_mpi_example.c -o simple_mpi_example -lfftw3_mpi -lfftw3 -lm
  </code></pre>
  
  <p>I am using older <code>gcc-5</code> for the compilation.</p>
  
  <p>I tried to run the same thing on a mac with gcc-8 and I did not have a problem. So I ran the same thing with a newer version of gcc on Ubuntu and still had the same issue.</p>
  
  <pre><code>#include &lt;fftw3-mpi.h&gt;
  
  int main(int argc, char **argv){
  const ptrdiff_t N0 = 10000, N1 = 10000;
  fftw_plan plan;
  fftw_complex *data; //local data of course
  ptrdiff_t alloc_local, local_n0, local_0_start, i, j;
  
  MPI_Init(&amp;argc, &amp;argv);
  fftw_mpi_init();
  
  /* get local data size and allocate */
  alloc_local = fftw_mpi_local_size_2d(N0, N1, MPI_COMM_WORLD,
                                    &amp;local_n0, &amp;local_0_start);
  data = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) *          
  alloc_local);
  
  printf("%i\n", local_n0);
  /* create plan for forward DFT */
  plan = fftw_mpi_plan_dft_2d(N0, N1, data, data, MPI_COMM_WORLD,
                           FFTW_FORWARD, FFTW_ESTIMATE);
  
  /* initialize data to some function my_function(x,y) */
  for (i = 0; i &lt; local_n0; ++i) for (j = 0; j &lt; N1; ++j){
    data[i*N1 + j][0]=local_0_start; 
    data[i*N1 + j][1]=i;
  }
  
  /* compute transforms, in-place, as many times as desired */
  fftw_execute(plan);
  
  fftw_destroy_plan(plan);
  fftw_free(data);
  MPI_Finalize();
  printf("finalize\n");
  return 0;
  }
  </code></pre>
  
  <p>When I compile it, the output is as follows</p>
  
  <pre><code>simple_mpi_example.c:18:10: warning: format ‘%i’ expects argument of 
  type ‘int’, but argument 2 has type ‘ptrdiff_t {aka long int}’ [-
  Wformat=]
  printf("%i\n", local_n0);
        ^
  /usr/local/lib/libfftw3_mpi.a(api.o): In function `bogosity_hook':
  api.c:(.text+0x2c): undefined reference to `ompi_mpi_comm_null'
  /usr/local/lib/libfftw3_mpi.a(api.o): In function `nowisdom_hook':
  api.c:(.text+0x8c): undefined reference to `ompi_mpi_comm_null'
  /usr/local/lib/libfftw3_mpi.a(api.o): In function `wisdom_ok_hook':
  api.c:(.text+0x110): undefined reference to `ompi_mpi_comm_null'
  api.c:(.text+0x1bb): undefined reference to `ompi_mpi_unsigned'
  api.c:(.text+0x1f8): undefined reference to `ompi_mpi_op_land'
  api.c:(.text+0x1ff): undefined reference to `ompi_mpi_int'
  /usr/local/lib/libfftw3_mpi.a(api.o): In function `cost_hook':
  api.c:(.text+0x29c): undefined reference to `ompi_mpi_comm_null'
  api.c:(.text+0x2a8): undefined reference to `ompi_mpi_op_sum'
  api.c:(.text+0x2b6): undefined reference to `ompi_mpi_op_max'
  api.c:(.text+0x2cb): undefined reference to `ompi_mpi_double'
  /usr/local/lib/libfftw3_mpi.a(transpose-alltoall.o): In function                 
  `apply':
  transpose-alltoall.c:(.text+0x95): undefined reference to     
  `ompi_mpi_double'
  transpose-alltoall.c:(.text+0x125): undefined reference to     
  `ompi_mpi_double'
  transpose-alltoall.c:(.text+0x16c): undefined reference to 
  `ompi_mpi_double'
  transpose-alltoall.c:(.text+0x19e): undefined reference to 
  `ompi_mpi_double'
  /usr/local/lib/libfftw3_mpi.a(transpose-pairwise.o):transpose-    
  pairwise.c:(.text+0x34a): more undefined references to 
  `ompi_mpi_double' follow
  /usr/local/lib/libfftw3_mpi.a(any-true.o): In function 
  `fftw_mpi_any_true':
  any-true.c:(.text+0x2d): undefined reference to `ompi_mpi_op_lor'
  any-true.c:(.text+0x34): undefined reference to `ompi_mpi_int'
  /tmp/ccHXT0fP.o: In function `main':
  simple_mpi_example.c:(.text+0x5f): undefined reference to 
  `ompi_mpi_comm_world'
  simple_mpi_example.c:(.text+0xba): undefined reference to 
  `ompi_mpi_comm_world'
  /usr/local/lib/libmpi.a(mpl_bt.o): In function `backtrace_libback':
  mpl_bt.c:(.text+0x110): undefined reference to 
  `backtrace_create_state'
  mpl_bt.c:(.text+0x129): undefined reference to `backtrace_print'
  /usr/local/lib/libmpi.a(ad_iwrite.o): In function 
  `ADIOI_GEN_aio_wait_fn':
  ad_iwrite.c:(.text+0x147): undefined reference to `aio_suspend'
  ad_iwrite.c:(.text+0x19a): undefined reference to `aio_error'
  ad_iwrite.c:(.text+0x1ad): undefined reference to `aio_return'
  /usr/local/lib/libmpi.a(ad_iwrite.o): In function 
  `ADIOI_GEN_aio_poll_fn':
  ad_iwrite.c:(.text+0x336): undefined reference to `aio_error'
  ad_iwrite.c:(.text+0x355): undefined reference to `aio_return'
  /usr/local/lib/libmpi.a(ad_iwrite.o): In function `ADIOI_GEN_aio':
  ad_iwrite.c:(.text+0x470): undefined reference to `aio_write'
  ad_iwrite.c:(.text+0x4c9): undefined reference to `aio_read'
  collect2: error: ld returned 1 exit status
  Makefile:4: recipe for target 'simple_mpi_example' failed
  make: *** [simple_mpi_example] Error 1
  </code></pre>