I inherited a rather large project that I am trying to get to compile (it's a bit old, maybe 10 years). I am trying to use new intel compilers with intel mpi on Ubuntu WSL.
There are some C modules and some fortran modules that I compile like so:
C Module:
mpiicc -g -DUSE_MPI_IO -Dlinux -DUse_Intel_Fortran -MP -D_FILE_OFFSET_BITS=64 -w -DLONG64 -O -L/home/xxx/intel/2024.2.1/oneapi/mpi/latest/lib -D__MPI__ -I/home/xxx/intel/2024.2.1/oneapi/mpi/latest/include -I. -c -o module_a.o module_a.c
Fortran Module:
mpiifort -g -c -I. -DUse_Intel_Fortran -MP -w -O -D__MPI__ -I/home/xxxx/intel/2024.2.1/oneapi/mpi/latest/include -L/home/xxx/intel/2024.2.1/oneapi/mpi/latest/lib module_b.f90
These compile just fine, but then I try to link these objects to the c compiler:
mpiicc -g -v -O -o final.x module_a.o module_b.o -lm -lmpi -L/home/xxx/intel/2024.2.1/oneapi/mpi/latest/lib
And I get a bunch of undefined reference MPI errors only for the fortran modules:
module_b.o:(.text+0x1838c): undefined reference to "mpi_send_"
module_b.o:(.text+0x1838c): undefined reference to "mpi_abort_"
Seems like I'm doing something stupid, but I can't find many other cases of people doing this for reference.
Any help is appreciated!
edit to correct a mistake, the errors are only for the fortran modules, not the C modules
-o -Idoesn't look right. Your binary will be named -I. You don't need -I for linking. Two possible approaches to solve your missing symbols: use the Fortran compiler for linking. It might require an extra flag to tell the Fortran compiler to do not generate a main function if that comes from C. Alternatively, you will need to explicitly link the MPI Fortran library. Find out, what mpiifort links additionally by checkingifort -showmpiifort). If not, you need to manually link with the Fortran MPI library (e.g.-lmpifort)