0

I am trying to compile a simple fortran program that uses libxc.

PROGRAM example_basicF90

   USE xc_f90_lib_m ! XCs, types and functions

   IMPLICIT NONE

   INTEGER :: i, vmajor, vminor, vmicro

   CALL xc_f90_version(vmajor, vminor, vmicro)
   WRITE(*,100) vmajor, vminor, vmicro

100 FORMAT("Libxc version: ",I1,"."I1"."I1)

END PROGRAM

I have compiled libxc using gcc/9.2.0 following the instructions provided on the git repo Without any issues

./configure --prefix=/scratch/Applications/libxc/libxc-6.0.0/GCC
make
make check 
make install

The issue I encounter is when I try to compile the simple code.

export LD_LIBXC=/scratch/Applications/libxc/libxc-6.0.0/GCC
gfortran -o example_basic -L${LD_LIBXC}/lib -lxcf90 -lxc -I${LD_LIBXC}/include example_basic.f90

example_basic.f90:(.text+0x1e): undefined reference to `__xc_f90_lib_m_MOD_xc_f90_version'

I double checked the lib and include directories for the correct files, and everything seems appropriate:

ls ${LD_LIBXC}/lib
libxc.a  libxcf03.a  libxcf03.la  libxcf90.a  libxcf90.la  libxc.la  pkgconfig

$ ls ${LD_LIBXC}/include
libxc.bib  xc_f03_lib_m.mod  xc_f90_lib_m.mod  xc_funcs.h  xc_funcs_removed.h  xc_funcs_worker.h  xc.h  xc_version.h

Any help is appreciated. Thanks

  • Which library do you think contains `__xc_f90_lib_m_MOD_xc_f90_version` and have you checked that it does? – francescalus Dec 14 '22 at 16:29
  • Hi, @francescalus thanks... so `__xc_f90_lib_m_MOD_xc_f90_version` should be inside `libxcf90.a`. I able able to locate the subroutine `xc_f90_version` under `${LD_LIBXC}/src/libxcf90.f90` which should also produce the module file `xc_f90_lib_m` – Joshua Elliott Dec 14 '22 at 16:53
  • And you've confirmed that `__xc_f90_lib_m_MOD_xc_f90_version` is defined in `${LD_LIBXC}/lib/libxcf90.a`? – francescalus Dec 14 '22 at 17:53
  • Yes, a look at the external symbols shows that it is there: ```$ nm -g libxcf90.a | grep version 00000000000023e0 T __xc_f90_lib_m_MOD_xc_f90_version 00000000000020f0 T __xc_f90_lib_m_MOD_xc_f90_version_string U xc_version U xc_version_string``` – Joshua Elliott Dec 14 '22 at 18:02
  • In which case you may simply need to ensure that `example_basic.f90` is given to the compiler/linked earlier in the command line than the library itself. As in this [other answer](https://stackoverflow.com/a/14978800/3157076). – francescalus Dec 14 '22 at 18:28
  • @francescalus this has fixed the issue I was experiencing. Thanks for your help! – Joshua Elliott Dec 14 '22 at 19:51

0 Answers0