meam package problems in building lammps as a library

Hi,

I am going to use the meam potential. I build the MEAM package as the way in the readme file and it works in LAMMPS.

The problem is that I am going to build lammps as a library and use it by my own code. I did it in this way:

Hi,

I am going to use the meam potential. I build the MEAM package as the way
in the readme file and it works in LAMMPS.

The problem is that I am going to build lammps as a library and use it by
my own code. I did it in this way:

make -f Makefile.gfortran
and I changed the Makefile.lammps file as: meam_SYSPATH = -L/opt/intel-11.1.046/lib/intel64
make yes-meam
make mpi mode=lib

I got the file liblammps_mpi.a. in directory src.

Then, I compile my own code which will call lammps to calculate meam potential in this way: mpic++ mycode.c -L /home/jinping/lammps-30Jul16/src -llammps_mpi -I /home/jinping/lammps-30Jul16/src -o mycode.out

It reports some errors and no executable file is produced. The output are as follows:

/tmp/ccKl2QVz.o: In function `LAMMPS_NS::PairMEAM::~PairMEAM()':
pair_meam.cpp:(.text+0x283): undefined reference to `meam_cleanup_'
/tmp/ccKl2QVz.o: In function `LAMMPS_NS::PairMEAM::compute(int, int)':
pair_meam.cpp:(.text+0x17c9): undefined reference to `meam_dens_init_'
pair_meam.cpp:(.text+0x1b30): undefined reference to `meam_dens_final_'
pair_meam.cpp:(.text+0x2037): undefined reference to `meam_force_'
/tmp/ccKl2QVz.o: In function `LAMMPS_NS::PairMEAM::coeff(int, char**)':
pair_meam.cpp:(.text+0x2559): undefined reference to `meam_setup_done_'
/tmp/ccKl2QVz.o: In function `LAMMPS_NS::PairMEAM::read_files(char*, char*)':
pair_meam.cpp:(.text+0x3793): undefined reference to `meam_setup_global_'
pair_meam.cpp:(.text+0x4017): undefined reference to `meam_setup_param_'
collect2: ld returned 1 exit status

So, how to solve this problem? And why there are no errors in the MEAM package when I only use it for lammps?

​because when you build the LAMMPS executable, you also link to the MEAM
library in the lib folder, but when you build your own program you don't.​
please study the command line carefully and re-read the manual.

axel

Hi Axel,

I recompiled my code as follows: mpic++ lj.c -L /home/jinping/lammps-30Jul16/lib/meam -L /home/jinping/lammps-30Jul16/src -llammps_mpi -I /home/jinping/lammps-30Jul16/src -I /home/jinping/lammps-30Jul16/lib/meam -o lj.out

it still outputs:

/home/jinping/lammps-30Jul16/src/liblammps_mpi.a(pair_meam.o): In function LAMMPS_NS::PairMEAM::read_files(char*, char*)': /home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:605: undefined reference to meam_setup_global_’
/home/jinping/lammps-30Jul16/src/Obj_mpi/…/pair_meam.cpp:720: undefined reference to meam_setup_param_' /home/jinping/lammps-30Jul16/src/liblammps_mpi.a(pair_meam.o): In function LAMMPS_NS::PairMEAM::coeff(int, char**)’:
/home/jinping/lammps-30Jul16/src/Obj_mpi/…/pair_meam.cpp:369: undefined reference to meam_setup_done_' /home/jinping/lammps-30Jul16/src/liblammps_mpi.a(pair_meam.o): In function ~PairMEAM’:
/home/jinping/lammps-30Jul16/src/Obj_mpi/…/pair_meam.cpp:79: undefined reference to meam_cleanup_' /home/jinping/lammps-30Jul16/src/liblammps_mpi.a(pair_meam.o): In function LAMMPS_NS::PairMEAM::compute(int, int)’:
/home/jinping/lammps-30Jul16/src/Obj_mpi/…/pair_meam.cpp:244: undefined reference to meam_dens_init_' /home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:259: undefined reference to meam_dens_final_’
/home/jinping/lammps-30Jul16/src/Obj_mpi/…/pair_meam.cpp:287: undefined reference to `meam_force_’
collect2: ld returned 1 exit status

So, what’s the problem

Thank you

Jinping

Hi Axel,

I recompiled my code as follows: mpic++ lj.c -L
/home/jinping/lammps-30Jul16/lib/meam -L /home/jinping/lammps-30Jul16/src
-llammps_mpi -I /home/jinping/lammps-30Jul16/src -I
/home/jinping/lammps-30Jul16/lib/meam -o lj.out

it still outputs:

/home/jinping/lammps-30Jul16/src/liblammps_mpi.a(pair_meam.o): In
function `LAMMPS_NS::PairMEAM::read_files(char*, char*)':
/home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:605: undefined
reference to `meam_setup_global_'
/home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:720: undefined
reference to `meam_setup_param_'
/home/jinping/lammps-30Jul16/src/liblammps_mpi.a(pair_meam.o): In
function `LAMMPS_NS::PairMEAM::coeff(int, char**)':
/home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:369: undefined
reference to `meam_setup_done_'
/home/jinping/lammps-30Jul16/src/liblammps_mpi.a(pair_meam.o): In
function `~PairMEAM':
/home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:79: undefined
reference to `meam_cleanup_'
/home/jinping/lammps-30Jul16/src/liblammps_mpi.a(pair_meam.o): In
function `LAMMPS_NS::PairMEAM::compute(int, int)':
/home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:244: undefined
reference to `meam_dens_init_'
/home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:259: undefined
reference to `meam_dens_final_'
/home/jinping/lammps-30Jul16/src/Obj_mpi/../pair_meam.cpp:287: undefined
reference to `meam_force_'
collect2: ld returned 1 exit status

So, what's the problem

​same as before.​