GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.lammps.org — 3.4. Link LAMMPS as a library to another code — LAMMPS documentation 3.4. Link LAMMPS as a library to another codeLAMMPS is designed as a library of C++ objects that can be integrated
into other applications, including Python scripts. The files
The Basic build options page explains how to build LAMMPS as either a
shared or static library. This results in a file in the compilation
folder called Note Care should be taken to use the same MPI library for the calling code and the LAMMPS library, unless LAMMPS is to be compiled without (real) MPI support using the included STUBS MPI library. 3.4.1. Link with LAMMPS as a static libraryThe calling application can link to LAMMPS as a static library with
compilation and link commands, as in the examples shown below. These
are examples for a code written in C in the file This assumes that LAMMPS has been configured without setting a
mpicc -c -O $(pkg-config --cflags liblammps) caller.c mpicxx -o caller caller.o -$(pkg-config --libs liblammps) This assumes that LAMMPS has been compiled in the folder
mpicc -c -O -I${HOME}/lammps/src caller.c mpicxx -o caller caller.o -L${HOME}/lammps/src -llammps_mpi The However, it is only as simple as shown above for the case of a plain LAMMPS library without any optional packages that depend on libraries (bundled or external) or when using a shared library. Otherwise, you need to include all flags, libraries, and paths for the coupled executable, that are also required to link the LAMMPS executable. When using CMake, additional libraries with sources in the lib
folder are built, but not included in Changed in version 10Sep2025. The traditional make build process no longer supports building
packages that require extra build steps in the 3.4.2. Link with LAMMPS as a shared libraryWhen linking to LAMMPS built as a shared library, the situation becomes
much simpler, as all dependent libraries and objects are either included
in the shared library or registered as a dependent library in the shared
library file. Thus, those libraries need not be specified when linking
the calling executable. Only the The commands with a shared LAMMPS library compiled with the CMake build process are the same as for the static library. mpicc -c -O $(pkg-config --cflags liblammps) caller.c mpicxx -o caller caller.o -$(pkg-config --libs liblammps) The commands with a shared LAMMPS library compiled with the
traditional make build using gcc -c -O -I${HOME}/lammps/src caller.c g++ -o caller caller.o -L${HOME}/lammps/src -llammps_serial Locating liblammps.so at runtimeUnlike with a static link, now the printenv LD_LIBRARY_PATH
to see what directories are in that list. Or you can add the LAMMPS src directory or the directory you performed a
CMake style build in to your For the Bourne or Korn shells (/bin/sh, /bin/ksh, /bin/bash etc.), you
would add something like this to your LD_LIBRARY_PATH=${LD_LIBRARY_PATH-/usr/lib64}:${HOME}/lammps/src export LD_LIBRARY_PATH For the csh or tcsh shells, you would equivalently add something like this
to your setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${HOME}/lammps/src You can verify whether all required shared libraries are found with the
LD_LIBRARY_PATH=/home/user/lammps/src ldd caller linux-vdso.so.1 (0x00007ffe729e0000) liblammps.so => /home/user/lammps/src/liblammps.so (0x00007fc91bb9e000) libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc91b984000) libm.so.6 => /lib64/libm.so.6 (0x00007fc91b83e000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc91b824000) libc.so.6 => /lib64/libc.so.6 (0x00007fc91b65b000) /lib64/ld-linux-x86-64.so.2 (0x00007fc91c094000) If a required library is missing, you would get a ‘not found’ entry: ldd caller linux-vdso.so.1 (0x00007ffd672fe000) liblammps.so => not found libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fb7c7e86000) libm.so.6 => /usr/lib64/libm.so.6 (0x00007fb7c7d40000) libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x00007fb7c7d26000) libc.so.6 => /usr/lib64/libc.so.6 (0x00007fb7c7b5d000) /lib64/ld-linux-x86-64.so.2 (0x00007fb7c80a2000) |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |