wvn
wvn

Reputation: 675

Mixed Fortran/C++ with intel compilers: undefined references to 'system_'

I am working on a large mixed-language code in Fortran 1990 and C++ 11. I recently compiled on a new platform with intel compilers (which I have successfully used before), specifically Intel Version 19.1.1.217.

I have boiled the issue down to a simple test:

f.F90

subroutine ff()

  implicit none
  call system('echo y')

end subroutine ff

main.cc

#include <iostream>
extern "C"
{
  void ff_(void);
}
int main(void)
{
  ff_();
  return 0;
}

I have emulated exactly how my code is built, which boils down to this:

mpif90 -f90=ifort -c f.F90 -o f.o
mpicxx -cxx=icpc -c main.cc -o main.o
mpicxx -cxx=icpc main.o f.o -L/software/intel/2020.1/compilers_and_libraries/linux/lib/intel64 -lifcore

...after which I get the following:

f.o: In function `ff_':
f.F90:(.text+0xd): undefined reference to `system_'

I am aware that calls to system() are not part of the stardard, but I can successfully compile and run the following with no problem:

p.F90:

program ff

  implicit none
  call system('echo y')

end program

mpif90 -f90=ifort p.f90 -o pexe && ./pexe

y

This suggests to me that using mpif90 -f90=ifort is imlicitly telling the linker to link in some extra libraries, but running ldd on the resulting executable shows a subset of the libraries linked in when I compile a simple C++ program.

What do I need to link to stop this error?

Upvotes: 2

Views: 283

Answers (1)

wvn
wvn

Reputation: 675

Well, I stumbled upon the solution immediately after asking this question. By using mpif90 -f90=ifort -v (source files) I was able to see everything that was being linked, and tried each library one at a time until it worked.

Upvotes: 2

Related Questions