edit Makefile to include static/dynamic libraries

Hello,

I have an external folder, including source codes and both static .a/dynamic .so libraries file, that I would like to include when compiling LAMMPS. The folder includes .cpp, .hpp, .inl files and many linker .o object files. Here is the source code of the Makefile I’m trying to edit:

Hello,

I have an external folder, including source codes and both static .a/dynamic
.so libraries file, that I would like to include when compiling LAMMPS. The
folder includes .cpp, .hpp, .inl files and many linker .o object files. Here
is the source code of the Makefile I'm trying to edit:

wouldn't it be much better to set this all up similar to one of the
library folders in the lib directory?
...and then only put the style source files into the src directory (or
better yet, make it a package).
you can follow the example of one of the existing packages with libraries.

axel.

Hello Axel,

Thank you for your comment. I actually looked at several optional packages, and went to the conclusion that my additional package directory is too big compared to typical lammps packages. It contained about 1916 files with ~30MB in total; so I don’t think combining 2 source codes is a good choice. However, I was able to build static and dynamic libraries. Is it possible to include the library in the Makefile somehow?

Thanks again,
Anh

Hello Axel,

Thank you for your comment. I actually looked at several optional packages, and went to the conclusion that my additional package directory is too big compared to typical lammps packages. It contained about 1916 files with ~30MB in total; so I don’t think combining 2 source codes is a good choice. However, I was able to build static and dynamic libraries. Is it possible to include the library in the Makefile somehow?

Please re-read my answer. You obviously didn’t quite get what I wrote. The answer is yes and you don’t have to edit the main makefile for that.

Hi,

Thank you for your comment. I actually looked at several optional packages,
and went to the conclusion that my additional package directory is too big
compared to typical lammps packages. It contained about 1916 files with
~30MB in total; so I don't think combining 2 source codes is a good choice.
However, I was able to build static and dynamic libraries. Is it possible
to include the library in the Makefile somehow?

The point that is made, if I understand correctly, is merely that other persons
are already doing what you are doing and that you can follow this example.

In short: put your external code in 'lib' and compile it there, put your
pair/fix/bond/etc styles in 'src'. Follow what is done in the Makefiles of others
to embed your modifications into lammps.

Regards,

Pierre

​Thanks again for pointing it out. ​I observe that in every Install.sh in lammps package, there is always a section of code

​Thanks again for pointing it out. ​I observe that in every Install.sh in lammps package, there is always a section of code


Install/unInstall package files in LAMMPS

mode = 0/1/2 for uninstall/install/update

mode=$1

arg1 = file, arg2 = file it depends on

action () {
if (test $mode = 0) then
rm -f …/$1
elif (! cmp -s $1 …/$1) then
if (test -z “$2” || test -e …/$2) then
cp $1 …
if (test $mode = 2) then
echo " updating src/$1"
fi
fi
elif (test -n “$2”) then
if (test ! -e …/$2) then
rm -f …/$1
fi
fi
}


follow by
action .cpp .h.

This Install.sh shell script would modify Makefile.package and add the source of the library directory into the Makefile.
Then using command:

make yes-

then compile lammps.

Does it sound like a correct way to do so?

It still sounds confused. Look at packages like meam, poems, gpu, user-atc. Particularly the last two as examples for big add-on packages that require additional libraries and have most of the code not in the package itself.

What does your 2000-file package do? Presumably most

of it is not LAMMPS style files, but your own stuff.

So you can separate it into 2 parts. Small = the LAMMPS

style files. Big = everything else.

Build Big as a library, independent

of LAMMPS, in some dir of your own.

Then make a copy of the normal LAMMPS machine Makefile.foo

that you use and put it in src/MAKE/Mine with a new suffix,

e.g. Makefile.myfoo.

Now edit that file and add your lib and its location to the LIB and

LINKFLAGS variables at the top of the file. Which is the

same thing that is happening for any other lib files LAMMPS

is linking against (MPI, FFTW, libraries in the LAMMPS lib/* dirs).

Now put the Small files in the LAMMPS src dir and build

LAMMPS as “make myfoo”. This will compile your Small files and link to your lib

and create lmp_myfoo.

If you put your Small files in a src/PACKAGE-DIR

then you can make it work like packages in LAMMPS do,

but you don’t have to do that, if you prefer to just

do it manually in your own version of LAMMPS.

Steve