linker - Linking legacy Fortran95 library to C++ with ifort/icpc -
background: in situation have make use of old fortran95 library in new c++ project. f95 library extensive, has tons of small modules, poorly documented, , auto-generated decade ago obscure computer algebra system (by people on different continent). heirloom code, works , irreplaceable.
luckily have source code , can compiled current versions of ifort, not familiar fortran, , rather not touch old code in significant way.
so suppose have fortran code (pes_shell.f90):
subroutine pes_init() use pes,wp=>pes_wp implicit none real,parameter::auang=0.5291772083 call pes0_init (dir='coef') call pes1_init (pes_x3y1z1u1_sysall) return end subroutine pes_init
the functions pes0_init(...) , pes1_init(...) lead abyssal depths of fortran library , contained in pes module.
i can compile object file, if give ifort path modules:
ifort -r8 -o2 -c pes_shell.f90 -i/home/debianuser/pes/pes_library/lib/mod
my poc c++ code, calling pes_init():
extern "c"{ void pes_init_(); } int main(){ pes_init_(); return 0; }
this can compiled object file, icpc:
icpc -c pestest.cpp
however cannot figure out how link 2 object files, plus truckload of fortran modules, final executable. have tried using icpc, cannot seem able find fortran functions, if give location of module files:
icpc -i/home/debianuser/pes/pes_library/lib/mod -o test.x pes_shell.o pestest.o pes_shell.o: in function `pes_shell_mp_f_': pes_shell.f90:(.text+0x595): undefined reference `pes_x3y1z1u1_mp_pes_x3y1z1u1_pot_' pes_shell.o: in function `pes_shell_mp_pes_init_': pes_shell.f90:(.text+0x5f0): undefined reference `pes0_mp_pes0_init_' pes_shell.f90:(.text+0x603): undefined reference `pes1c_mp_pes1_init_' pestest.o: in function `main': pestest.cpp:(.text+0x2b): undefined reference `pes_init_'
edit: pointing linker directory libpes.a can found eliminates problem of locating function referenced in c++ code, icpc still cannot find fortran functions being called fortran codes:
icpc -i/home/debianuser/pes/pes_library/lib/mod -l/home/debianuser/pes/pes_library/lib/pes-xyz -lpes -o test.x pestest.o pes_shell_new.o pes_shell_new.o: in function `f_': pes_shell_new.f90:(.text+0x585): undefined reference `pes_x3y1z1u1_mp_pes_x3y1z1u1_pot_' pes_shell_new.o: in function `pes_init_': pes_shell_new.f90:(.text+0x5e0): undefined reference `pes0_mp_pes0_init_' pes_shell_new.f90:(.text+0x5f3): undefined reference `pes1c_mp_pes1_init_'
Comments
Post a Comment