OSX 10.11.6 KIM API v1.7.3 install error

I have been attempting to install the KIM API for use with LAMMPS for the past few days, but have run into the following issue:

One of the MEAM_2NN files throws a linker error about illegal text re-allocation:
ld: illegal text-relocation to ‘_reinit’ in libkim-api-model-driver-v1.7.3+GCC.darwin.64bit.dynamic-load.a(MEAM_2NN.o) from ‘anon’ in libkim-api-model-driver-v1.7.3+GCC.darwin.64bit.dynamic-load.a(MEAM_2NN.o) for architecture x86_64
collect2: error: ld returned 1 exit status
make[1]: *** [libkim-api-model-driver-v1.7.3+GCC.darwin.64bit.dynamic-load.so] Error 1
rm driver_init_wrapper.cpp export-list.txt
make: *** [MEAM_2NN__MD_111291751625_001-all] Error 2

I have tried this with gcc/g++ v4.8 and v6 (from homebrew, the latter actually reads 6.2.0 from --version), because the default compiler had a difficulty with fortran.

I have tried this with both dynamic-load and dynamic-link on 4.8. The same error results.

I have tried this after artificially changing the Makefile.KIM_Config file to 32 bit architecture (-m32 flags included…this throws a different error, but still errors):
ld: warning: ignoring file build-config.o, file was built for x86_64 which is not the architecture being linked (i386): build-config.o
Undefined symbols for architecture i386:
“_main”, referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status
make[1]: *** [kim-api-v1-build-config] Error 1

The makefile I use for compiling with gcc-6 is attached. Is this a known issue? Are there any workarounds?

Thank you for your help,

-Colin Campbell

Makefile.KIM_Config (365 Bytes)

Hi Colin,

Thanks for your message and sorry for the difficulty.

This is, in fact, a known bug in the gfortran compiler on the MacOS system.
We've reported it to the gfortran group but haven't seen much movement on a solution.

A previous post on this topic can be found here:

https://groups.google.com/d/msg/openkim/fxAAJeOC5UY/USep96FAu-EJ

For completness, Here I'll list the only currently known workaround (Similar details can be found at the above link and in the kim-api INSTALL file)

You must compile the kim-api in 32bit mode and provide a special linker command line argument.

Using the latest kim-api-1.7.3 release, you can setup the build with the following command (assuming the GCC compiler suite version 4.8 (this particular version should not be necessary) is installed with executables named gcc-4.8, g++-4.8 and gforgran-4.8):

$ ./configure "--system-arch=32bit" "CXX=g++-4.8" "CC=gcc-4.8" "FC=gfortran-4.8" "LDFLAGS+=-read_only_relocs suppress"

This will generate a Makefile.KIM_Config file with the following lines (in addition to a few other lines unrelated to this issue)

That seems to have done it, thank you!