Resolving Error "ld: library not found for -lgfortran"

Dear OpenKIM Users,

I’m trying to install the OpenKIM API in my MacBook (had already installed the KIM models), and getting the following error while following section “D” of Install document in documentation of OpenKIM API:

***************************************************************************=
***************************************************************************=


Jatins-Air:kim-api-v1.9.3 kashyap$ make

***************************************************************************=


*** Building… kim-api-objects =
=20


***************************************************************************=


make[1]: Nothing to be done for `objects’.

***************************************************************************=


*** Building… kim-api-libs =
=20


***************************************************************************=


Creating… KIM API library…=20
libkim-api-v1.9.3+GCC.darwin.64bit.dynamic-load.so.

ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see=20
invocation)

make[1]: *** [libkim-api-v1.9.3+GCC.darwin.64bit.dynamic-load.so] Error 1
make: *** [kim-api-libs] Error 2
***************************************************************************=
***************************************************************************=


I’m going to use it with LAMMPS on my local machine. And I already searched the forum for relevant content.

Thank you very much in advance for any hint to solve it.

By the way, I’m using macOS High Sierra v 10.13.1

Hi Jatin,

Thanks for your message. This can be a bit tricky on the MacOS... Can you provide a listing of your Makefile.KIM_Config file and the compiler (c, c++, and fortran) versions you are using?

Thanks,

Ryan

Hello Relliott,

I’m getting following for Makefile.KIM_Config search:

Jatins-Air:src kashyap$ locate Makefile.KIM_Config
/Users/kashyap/kim-api-v1.9.3/Makefile.KIM_Config
/Users/kashyap/kim-api-v1.9.3/Makefile.KIM_Config.example
/Users/kashyap/kim-api-v1.9.3/examples/model_drivers/Makefile.KIM_Config
/Users/kashyap/kim-api-v1.9.3/examples/models/Makefile.KIM_Config

And this one for the fortran compiler:

Jatins-Air:src kashyap$ gfortran --version
GNU Fortran (Homebrew GCC 7.3.0) 7.3.0
Copyright © 2017 Free Software Foundation, Inc.

Thank you very much for a quick, and informative reply.

I’m greatly sorry Ryan, I just realized my mistake of misinterpreting your name.
Thank you.

Hi Jatin,

No problem....

OK, I just tested it out and I was able to get it all to work using the following configuration command:

./configure --prefix=${HOME}/local --system-arch=32bit CC=gcc-7 CXX=g++-7 FC=gfortran-7 LDFLAGS+="-read_only_relocs suppress"

Explaination:

'--system-arch=32bit'

   Due to a gfortran bug on MacOS we can only get the KIM API to compile
   in 32 bit mode...

'CC=gcc-7'
'CXX=g++-7'
'FC=gfortran-7'

   These settings tell the build system how to find the correct compilers
   you have installed on your system. In your case these are the versions
   installed via homebrew.

'LDFLAGS+="-read_only_relocs suppress"'

   This setting works-around another bug in the gfortran compiler on
   MacOS.

For everyone's reference, these things are also explained in Section F.1(h) of the INSTALL file.

Try that configure command and see if it works for you now....

Cheers,

Ryan

Hello Ryan,

Thank you very much for a quick, and very informative reply. This time, I’m getting a new error as below

Jatins-MacBook-Air:~ kashyap$ kim-api-vX-collections-management install system --sudo EDIP_BOP_Bazant_Kaxiras_Si__MO_958932894036_001
-bash: kim-api-vX-collections-management: command not found

I had already installed wget and tar according to point # 5 of system requirements section of the install doc. I know it’s very trivial mistake but I’m not able to figure it out. Your help will be much appreciated.

Thank you for your time, and efforts.

Hi Jatin,

You need to replace the ‘X’ in ‘vX’ with the current major version of the
API you’re using. Check if ‘kim-api-v1-collections-management’ is on your
path and repeat the install command with that.

Dan

Hello Dan,

I repeated the install command after replacing the X with the major version number according to your instructions. Although I’m not sure about the second part of your answer. For the reference, I’m attaching the screenshot of my terminal showing important information.
Thank you for your time.

Hi Jatin,

Looks like the screenshot never got attached. What was the output of doing kim-api-v1-collections-management install system --sudo EDIP_BOP_Bazant_Kaxiras_Si__MO_958932894036_001?

The second part of my answer pertains to what your terminal was complaining about. Your “system path”, contained in the shell variable PATH, consists of all of the directories on your machine where your shell (bash, in this case) searches for commands to execute. You can view your current system path by entering echo $PATH (see here for reference). In this case, your shell was saying that command “kim-api-vX-collections-management” could not be found because it didn’t find any executable file with that name in any of those directories. This is simply because the actual executable file that the KIM API creates during installation is named “kim-api-v1-collections-management” in your case.

Hello Dan,

Thank you for a very informative reply. I’m sorry for the attachment. I’m copy-pasting the error here which is basically the same:

Jatins-MacBook-Air:~ kashyap$ kim-api-v1-collections-management install system --sudo EDIP_BOP_Bazant_Kaxiras_Si__MO_958932894036_001
-bash: kim-api-v1-collections-management: command not found

Did you remember to issue a `make install` after doing `make` to compile
the API?

Also,

Since you are installing to a non-standard directory you will need to "activate" (add to your PATH variable) the api.

There is now a utility for doing this:

source \./{HOME}/local/bin/kim-api-v1-activate

This will need to be done once in any shell that you want to use the kim-api utilities within. (Alternatively you put this command in one of your shell configuration files, such as ${HOME}/.bashrc)

Ryan

Sorry,
There is a typo, the correct command should be:

source {HOME}/local/bin/kim-api-v1-activate

Without the “./“ before “${HOME}”

Ryan

Hi Ryan,

Thanks for the help, and it really solved the problem which I was facing while installing KIM API. But now I’m facing problem while making lammps after installing kim package. When I go with the command “make mpi” to recompile the lammps, it throws me following error:

Jatins-MacBook-Air:src kashyap$ make mpi
…/…/lib/kim/Makefile.lammps:27: *** kim-api-build-config utility is not available. Something is wrong with your KIM API package setup. Stop.
…/…/lib/kim/Makefile.lammps:27: *** kim-api-build-config utility is not available. Something is wrong with your KIM API package setup. Stop.
make: *** [mpi] Error 2

Thank you for helping me out here.

Thanks for the help, and it really solved the problem which I was facing
while installing KIM API.

I'm glad you were able to get the KIM API working!

But now I'm facing problem while making
lammps after installing kim package. When I go with the command "make mpi"
to recompile the lammps, it throws me following error:

*Jatins-MacBook-Air:src kashyap$ make mpi*
*../../lib/kim/Makefile.lammps:27: *** kim-api-build-config utility is not
available. Something is wrong with your KIM API package setup. Stop.*
*../../lib/kim/Makefile.lammps:27: *** kim-api-build-config utility is not
available. Something is wrong with your KIM API package setup. Stop.*
*make: *** [mpi] Error 2*

OK, for this I'll need to know the specific version of LAMMPS you are using and what (if any) modifications you have made to the lammps makefile names "src/MAKE/Makefile.mpi".

(Any other changes you have made to the lammps files may also be helpful.)

Cheers,

Ryan

Hello Ryan,

I’m using “lammps-11Aug17”. The only change I had made to lammps is, I had added a new REBO potential (.cpp and .h files of it) to the src/ and then recompiled it which was working without any problem. Other then this I didn’t make any changes to it.

Please let me know if you need any other information.
Thank you.

Hi Jatin,

OK. For that version of LAMMPS you'll need to edit the lib/kim/Makefile.lammps file and change "kim-api-build-config" to "kim-api-v1-build-config" everywhere in that file.

I think that will fix the error you are having regarding "kim-api-build-config utility is not available"

However, the Makefile.mpi build uses the mpicxx compiler to build lammps. Since we used the g++-7 compiler to build the kim-api, I'm not sure if the lammps build with mpicxx will be successful.

I've never tried to do an mpi build, like this, on MacOS before. I'm afraid that if we run into problems at this point, it would require rather more experimentation and time to figure out how to get it to work...

But, maybe it will just work!

Good luck.

Ryan

Hi Ryan,

You’re right. That solved the “kim-api-build-config utility is not available” error. But now I’m getting a new error more towards the end of process of building LAMMPS which goes as follows:

ld: warning: ignoring file write_dump.o, file was built for x86_64 which is not the architecture being linked (i386): write_dump.o
ld: warning: ignoring file /usr/local/Cellar/open-mpi/3.0.0_2/lib/libmpi.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/open-mpi/3.0.0_2/lib/libmpi.dylib
Undefined symbols for architecture i386:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** […/lmp_mpi] Error 1
make: *** [mpi] Error 2

I think it’s due to the same compiler incompatibility issue that you had already described. Anyways, given the situation can you please help me with the below questions:

1.) Do you think, there will be no problem if I install Linux in VirtualBox hosted by my MacBook and then try to use KIM models in LAMMPS installed in that Linux OS? If so, then with which linux OS should I go ahead.

2.) I also have access to our university cluster which is having LAMMPS build upon Scientific Linux OS. But I noticed, to install the KIM API sudo command have to be used which can’t be used by me on our university cluster since I’m a student. Do you think there is any other option to install KIM API on university cluster(bypassing sudo command) other than asking the admin people?

Hi Ryan,

You're right. That solved the "kim-api-build-config utility is not
available" error.

Great.

1.) Do you think, there will be no problem if I install Linux in VirtualBox
hosted by my MacBook and then try to use KIM models in LAMMPS installed in
that Linux OS? If so, then with which linux OS should I go ahead.

Yes, this will be quite straight foward, and I think probably the best option.

I have just tested this on my mac using the standard Ubuntu64 Artful image (via vagrant and VirtualBox):

* perform any updates for the box.

* Install some dependencies:

$ sudo apt-get install make python g++ gfortran mpi-default-bin mpi-default-dev fftw-dev

* get the latest lammps:

$ wget http://lammps.sandia.gov/tars/lammps-8Mar18.tar.gz

* unpack it

$ tar xzvf lammps-8Mar18.tar.gz

* change dir

$ cd lammps-8Mar18/src

* build kim-api and install a model of interest (eg: Glue_Ercolessi_Adams_Al__MO_324507536345_001)

$ make lib-kim args="-v kim-api-v1.9.3 -b -a Glue_Ercolessi_Adams_Al__MO_324507536345_001"

* build lammps with kim support

make yes\-kim make mpi

* add anohter KIM model if desired (eg: Pair_Johnson_Fe__MO_857282754307_002)

$ source ../lib/kim/installed-kim-api-v1.9.3/bin/kim-api-v1-activate

$ kim-api-v1-collections-management install system Pair_Johnson_Fe__MO_857282754307_002

Cheers,

Ryan