356 lines
31 KiB
HTML
356 lines
31 KiB
HTML
<!DOCTYPE html>
|
||
<html class="writer-html5" lang="en" >
|
||
<head>
|
||
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>3.3. Link LAMMPS as a library to another code — LAMMPS documentation</title>
|
||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/sphinx-design.min.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/tabs.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/css/lammps.css" type="text/css" />
|
||
<link rel="shortcut icon" href="_static/lammps.ico"/>
|
||
<link rel="canonical" href="https://docs.lammps.org/Build_link.html" />
|
||
<!--[if lt IE 9]>
|
||
<script src="_static/js/html5shiv.min.js"></script>
|
||
<![endif]-->
|
||
|
||
<script src="_static/jquery.js?v=5d32c60e"></script>
|
||
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
||
<script src="_static/documentation_options.js?v=5929fcd5"></script>
|
||
<script src="_static/doctools.js?v=9bcbadda"></script>
|
||
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
<script src="_static/design-tabs.js?v=f930bc37"></script>
|
||
<script async="async" src="_static/mathjax/es5/tex-mml-chtml.js?v=cadf963e"></script>
|
||
<script src="_static/tabs.js?v=3030b3cb"></script>
|
||
<script src="_static/js/theme.js"></script>
|
||
<link rel="index" title="Index" href="genindex.html" />
|
||
<link rel="search" title="Search" href="search.html" />
|
||
<link rel="next" title="3.4. Basic build options" href="Build_basics.html" />
|
||
<link rel="prev" title="3.2. Build LAMMPS with make" href="Build_make.html" />
|
||
</head>
|
||
|
||
<body class="wy-body-for-nav">
|
||
<div class="wy-grid-for-nav">
|
||
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
||
<div class="wy-side-scroll">
|
||
<div class="wy-side-nav-search" >
|
||
|
||
|
||
|
||
<a href="Manual.html">
|
||
|
||
<img src="_static/lammps-logo.png" class="logo" alt="Logo"/>
|
||
</a>
|
||
<div class="lammps_version">Version: <b>19 Nov 2024</b></div>
|
||
<div class="lammps_release">git info: </div>
|
||
<div role="search">
|
||
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
||
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
|
||
<p class="caption" role="heading"><span class="caption-text">User Guide</span></p>
|
||
<ul class="current">
|
||
<li class="toctree-l1"><a class="reference internal" href="Intro.html">1. Introduction</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Install.html">2. Install LAMMPS</a></li>
|
||
<li class="toctree-l1 current"><a class="reference internal" href="Build.html">3. Build LAMMPS</a><ul class="current">
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_cmake.html">3.1. Build LAMMPS with CMake</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_make.html">3.2. Build LAMMPS with make</a></li>
|
||
<li class="toctree-l2 current"><a class="current reference internal" href="#">3.3. Link LAMMPS as a library to another code</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#link-with-lammps-as-a-static-library">3.3.1. Link with LAMMPS as a static library</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#link-with-lammps-as-a-shared-library">3.3.2. Link with LAMMPS as a shared library</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_basics.html">3.4. Basic build options</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_settings.html">3.5. Optional build settings</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_package.html">3.6. Include packages in build</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_extras.html">3.7. Packages with extra build options</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_manual.html">3.8. Build the LAMMPS documentation</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_windows.html">3.9. Notes for building LAMMPS on Windows</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_diskspace.html">3.10. Notes for saving disk space when building LAMMPS from source</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="Build_development.html">3.11. Development build options</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Run_head.html">4. Run LAMMPS</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Commands.html">5. Commands</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Packages.html">6. Optional packages</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Speed.html">7. Accelerate performance</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Howto.html">8. Howto discussions</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Examples.html">9. Example scripts</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Tools.html">10. Auxiliary tools</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Errors.html">11. Errors</a></li>
|
||
</ul>
|
||
<p class="caption" role="heading"><span class="caption-text">Programmer Guide</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="Library.html">1. LAMMPS Library Interfaces</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Python_head.html">2. Use Python with LAMMPS</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Modify.html">3. Modifying & extending LAMMPS</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Developer.html">4. Information for Developers</a></li>
|
||
</ul>
|
||
<p class="caption" role="heading"><span class="caption-text">Command Reference</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="commands_list.html">Commands</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="fixes.html">Fix Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="computes.html">Compute Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="pairs.html">Pair Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="bonds.html">Bond Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="angles.html">Angle Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="dihedrals.html">Dihedral Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="impropers.html">Improper Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="dumps.html">Dump Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="fix_modify_atc_commands.html">fix_modify AtC commands</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="Bibliography.html">Bibliography</a></li>
|
||
</ul>
|
||
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
<a href="Manual.html">LAMMPS</a>
|
||
</nav>
|
||
|
||
<div class="wy-nav-content">
|
||
<div class="rst-content style-external-links">
|
||
<div role="navigation" aria-label="Page navigation">
|
||
<ul class="wy-breadcrumbs">
|
||
<li><a href="Manual.html" class="icon icon-home" aria-label="Home"></a></li>
|
||
<li class="breadcrumb-item"><a href="Build.html"><span class="section-number">3. </span>Build LAMMPS</a></li>
|
||
<li class="breadcrumb-item active"><span class="section-number">3.3. </span>Link LAMMPS as a library to another code</li>
|
||
<li class="wy-breadcrumbs-aside">
|
||
<a href="https://www.lammps.org"><img src="_static/lammps-logo.png" width="64" height="16" alt="LAMMPS Homepage"></a> | <a href="Commands_all.html">Commands</a>
|
||
</li>
|
||
</ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
|
||
<a href="Build_make.html" class="btn btn-neutral float-left" title="3.2. Build LAMMPS with make" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
||
<a href="Build_basics.html" class="btn btn-neutral float-right" title="3.4. Basic build options" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
||
</div>
|
||
<hr/>
|
||
</div>
|
||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||
<div itemprop="articleBody">
|
||
|
||
<p><span class="math notranslate nohighlight">\(\renewcommand{\AA}{\text{Å}}\)</span></p>
|
||
<section id="link-lammps-as-a-library-to-another-code">
|
||
<h1><span class="section-number">3.3. </span>Link LAMMPS as a library to another code<a class="headerlink" href="#link-lammps-as-a-library-to-another-code" title="Link to this heading"></a></h1>
|
||
<p>LAMMPS is designed as a library of C++ objects that can be integrated
|
||
into other applications, including Python scripts. The files
|
||
<code class="docutils literal notranslate"><span class="pre">src/library.cpp</span></code> and <code class="docutils literal notranslate"><span class="pre">src/library.h</span></code> define a C-style API for using
|
||
LAMMPS as a library. See the <a class="reference internal" href="Howto_library.html"><span class="doc">Library interface to LAMMPS</span></a> page for a
|
||
description of the interface and how to use it for your needs.</p>
|
||
<p>The <a class="reference internal" href="Build_basics.html"><span class="doc">Basic build options</span></a> page explains how to build LAMMPS as either a
|
||
shared or static library. This results in a file in the compilation
|
||
folder called <code class="docutils literal notranslate"><span class="pre">liblammps.a</span></code> or <code class="docutils literal notranslate"><span class="pre">liblammps_<name>.a</span></code> in case of
|
||
building a static library. In case of a shared library, the name is the
|
||
same only that the suffix is going to be either <code class="docutils literal notranslate"><span class="pre">.so</span></code> or <code class="docutils literal notranslate"><span class="pre">.dylib</span></code> or
|
||
<code class="docutils literal notranslate"><span class="pre">.dll</span></code> instead of <code class="docutils literal notranslate"><span class="pre">.a</span></code> depending on the OS. In some cases, the
|
||
<code class="docutils literal notranslate"><span class="pre">.so</span></code> file may be a symbolic link to a file with the suffix <code class="docutils literal notranslate"><span class="pre">.so.0</span></code>
|
||
(or some other number).</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>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.</p>
|
||
</div>
|
||
<section id="link-with-lammps-as-a-static-library">
|
||
<h2><span class="section-number">3.3.1. </span>Link with LAMMPS as a static library<a class="headerlink" href="#link-with-lammps-as-a-static-library" title="Link to this heading"></a></h2>
|
||
<p>The 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 <code class="docutils literal notranslate"><span class="pre">caller.c</span></code>.
|
||
The benefit of linking to a static library is, that the resulting
|
||
executable is independent of that library since all required
|
||
executable code from the library is copied into the calling executable.</p>
|
||
<div class="sphinx-tabs docutils container">
|
||
<div aria-label="Tabbed content" class="closeable" role="tablist"><button aria-controls="panel-0-0-0" aria-selected="true" class="sphinx-tabs-tab" id="tab-0-0-0" name="0-0" role="tab" tabindex="0">CMake build</button><button aria-controls="panel-0-0-1" aria-selected="false" class="sphinx-tabs-tab" id="tab-0-0-1" name="0-1" role="tab" tabindex="-1">Traditional make</button></div><div aria-labelledby="tab-0-0-0" class="sphinx-tabs-panel" id="panel-0-0-0" name="0-0" role="tabpanel" tabindex="0"><p>This assumes that LAMMPS has been configured without setting a
|
||
<code class="docutils literal notranslate"><span class="pre">LAMMPS_MACHINE</span></code> name, installed with <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code>, and the
|
||
<code class="docutils literal notranslate"><span class="pre">PKG_CONFIG_PATH</span></code> environment variable has been updated to
|
||
include the <code class="docutils literal notranslate"><span class="pre">liblammps.pc</span></code> file installed into the configured
|
||
destination folder. The commands to compile and link a coupled
|
||
executable are then:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>mpicc<span class="w"> </span>-c<span class="w"> </span>-O<span class="w"> </span><span class="k">$(</span>pkg-config<span class="w"> </span>--cflags<span class="w"> </span>liblammps<span class="k">)</span><span class="w"> </span>caller.c
|
||
mpicxx<span class="w"> </span>-o<span class="w"> </span><span class="nb">caller</span><span class="w"> </span>caller.o<span class="w"> </span>-<span class="k">$(</span>pkg-config<span class="w"> </span>--libs<span class="w"> </span>liblammps<span class="k">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div><div aria-labelledby="tab-0-0-1" class="sphinx-tabs-panel" hidden="true" id="panel-0-0-1" name="0-1" role="tabpanel" tabindex="0"><p>This assumes that LAMMPS has been compiled in the folder
|
||
<code class="docutils literal notranslate"><span class="pre">${HOME}/lammps/src</span></code> with “make mpi”. The commands to compile
|
||
and link a coupled executable are then:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>mpicc<span class="w"> </span>-c<span class="w"> </span>-O<span class="w"> </span>-I<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/src<span class="w"> </span>caller.c
|
||
mpicxx<span class="w"> </span>-o<span class="w"> </span><span class="nb">caller</span><span class="w"> </span>caller.o<span class="w"> </span>-L<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/src<span class="w"> </span>-llammps_mpi
|
||
</pre></div>
|
||
</div>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">-I</span></code> argument is the path to the location of the <code class="docutils literal notranslate"><span class="pre">library.h</span></code>
|
||
header file containing the interface to the LAMMPS C-style library
|
||
interface. The <code class="docutils literal notranslate"><span class="pre">-L</span></code> argument is the path to where the
|
||
<code class="docutils literal notranslate"><span class="pre">liblammps_mpi.a</span></code> file is located. The <code class="docutils literal notranslate"><span class="pre">-llammps_mpi</span></code> argument
|
||
is shorthand for telling the compiler to link the file
|
||
<code class="docutils literal notranslate"><span class="pre">liblammps_mpi.a</span></code>. If LAMMPS has been built as a shared
|
||
library, then the linker will use <code class="docutils literal notranslate"><span class="pre">liblammps_mpi.so</span></code> instead.
|
||
If both files are available, the linker will usually prefer the
|
||
shared library. In case of a shared library, you may need to
|
||
update the <code class="docutils literal notranslate"><span class="pre">LD_LIBRARY_PATH</span></code> environment variable or running the
|
||
<code class="docutils literal notranslate"><span class="pre">caller</span></code> executable will fail since it cannot find the shared
|
||
library at runtime.</p>
|
||
</div></div>
|
||
<p>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.</p>
|
||
<div class="sphinx-tabs docutils container">
|
||
<div aria-label="Tabbed content" class="closeable" role="tablist"><button aria-controls="panel-1-1-0" aria-selected="true" class="sphinx-tabs-tab" id="tab-1-1-0" name="1-0" role="tab" tabindex="0">CMake build</button><button aria-controls="panel-1-1-1" aria-selected="false" class="sphinx-tabs-tab" id="tab-1-1-1" name="1-1" role="tab" tabindex="-1">Traditional make</button></div><div aria-labelledby="tab-1-1-0" class="sphinx-tabs-panel" id="panel-1-1-0" name="1-0" role="tabpanel" tabindex="0"><p>When using CMake, additional libraries with sources in the lib
|
||
folder are built, but not included in <code class="docutils literal notranslate"><span class="pre">liblammps.a</span></code> and
|
||
(currently) not installed with <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code> and not included
|
||
in the <code class="docutils literal notranslate"><span class="pre">pkgconfig</span></code> configuration file. They can be found in the
|
||
top level build folder, but you have to determine the necessary
|
||
link flags manually. It is therefore recommended to either use
|
||
the traditional make procedure to build and link with a static
|
||
library or build and link with a shared library instead.</p>
|
||
</div><div aria-labelledby="tab-1-1-1" class="sphinx-tabs-panel" hidden="true" id="panel-1-1-1" name="1-1" role="tabpanel" tabindex="0"><p>After you have compiled a static LAMMPS library using the
|
||
conventional build system for example with “make mode=static
|
||
serial”. And you also have installed the <code class="docutils literal notranslate"><span class="pre">POEMS</span></code> package after
|
||
building its bundled library in <code class="docutils literal notranslate"><span class="pre">lib/poems</span></code>. Then the commands
|
||
to build and link the coupled executable change to:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>gcc<span class="w"> </span>-c<span class="w"> </span>-O<span class="w"> </span>-I<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/src<span class="w"> </span>-caller.c
|
||
g++<span class="w"> </span>-o<span class="w"> </span><span class="nb">caller</span><span class="w"> </span>caller.o<span class="w"> </span>-L<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/lib/poems<span class="w"> </span><span class="se">\</span>
|
||
<span class="w"> </span>-L<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/src/STUBS<span class="w"> </span>-L<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/src<span class="w"> </span><span class="se">\</span>
|
||
<span class="w"> </span>-llammps_serial<span class="w"> </span>-lpoems<span class="w"> </span>-lmpi_stubs
|
||
</pre></div>
|
||
</div>
|
||
<p>Note, that you need to link with <code class="docutils literal notranslate"><span class="pre">g++</span></code> instead of <code class="docutils literal notranslate"><span class="pre">gcc</span></code> even
|
||
if you have written your code in C, since LAMMPS itself is C++
|
||
code. You can display the currently applied settings for building
|
||
LAMMPS for the “serial” machine target by using the command:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>make<span class="w"> </span><span class="nv">mode</span><span class="o">=</span>print<span class="w"> </span>serial
|
||
</pre></div>
|
||
</div>
|
||
<p>Which should output something like:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># Compiler:</span>
|
||
<span class="nv">CXX</span><span class="o">=</span>g++
|
||
<span class="c1"># Linker:</span>
|
||
<span class="nv">LD</span><span class="o">=</span>g++
|
||
<span class="c1"># Compilation:</span>
|
||
<span class="nv">CXXFLAGS</span><span class="o">=</span>-g<span class="w"> </span>-O3<span class="w"> </span>-DLAMMPS_GZIP<span class="w"> </span>-DLAMMPS_MEMALIGN<span class="o">=</span><span class="m">64</span><span class="w"> </span>-I<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/compile/lammps/lib/poems<span class="w"> </span>-I<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/compile/lammps/src/STUBS
|
||
<span class="c1"># Linking:</span>
|
||
<span class="nv">LDFLAGS</span><span class="o">=</span>-g<span class="w"> </span>-O
|
||
<span class="c1"># Libraries:</span>
|
||
<span class="nv">LDLIBS</span><span class="o">=</span>-L<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/compile/lammps/src<span class="w"> </span>-llammps_serial<span class="w"> </span>-L<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/compile/lammps/lib/poems<span class="w"> </span>-L<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/compile/lammps/src/STUBS<span class="w"> </span>-lpoems<span class="w"> </span>-lmpi_stubs
|
||
</pre></div>
|
||
</div>
|
||
<p>From this you can gather the necessary paths and flags. With
|
||
makefiles for other <em>machine</em> configurations you need to do the
|
||
equivalent and replace “serial” with the corresponding “machine”
|
||
name of the makefile.</p>
|
||
</div></div>
|
||
</section>
|
||
<section id="link-with-lammps-as-a-shared-library">
|
||
<h2><span class="section-number">3.3.2. </span>Link with LAMMPS as a shared library<a class="headerlink" href="#link-with-lammps-as-a-shared-library" title="Link to this heading"></a></h2>
|
||
<p>When 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 <code class="docutils literal notranslate"><span class="pre">-I</span></code> flags are needed. So the example
|
||
case from above of the serial version static LAMMPS library with the
|
||
POEMS package installed becomes:</p>
|
||
<div class="sphinx-tabs docutils container">
|
||
<div aria-label="Tabbed content" class="closeable" role="tablist"><button aria-controls="panel-2-2-0" aria-selected="true" class="sphinx-tabs-tab" id="tab-2-2-0" name="2-0" role="tab" tabindex="0">CMake build</button><button aria-controls="panel-2-2-1" aria-selected="false" class="sphinx-tabs-tab" id="tab-2-2-1" name="2-1" role="tab" tabindex="-1">Traditional make</button></div><div aria-labelledby="tab-2-2-0" class="sphinx-tabs-panel" id="panel-2-2-0" name="2-0" role="tabpanel" tabindex="0"><p>The commands with a shared LAMMPS library compiled with the CMake
|
||
build process are the same as for the static library.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>mpicc<span class="w"> </span>-c<span class="w"> </span>-O<span class="w"> </span><span class="k">$(</span>pkg-config<span class="w"> </span>--cflags<span class="w"> </span>liblammps<span class="k">)</span><span class="w"> </span>caller.c
|
||
mpicxx<span class="w"> </span>-o<span class="w"> </span><span class="nb">caller</span><span class="w"> </span>caller.o<span class="w"> </span>-<span class="k">$(</span>pkg-config<span class="w"> </span>--libs<span class="w"> </span>liblammps<span class="k">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</div><div aria-labelledby="tab-2-2-1" class="sphinx-tabs-panel" hidden="true" id="panel-2-2-1" name="2-1" role="tabpanel" tabindex="0"><p>The commands with a shared LAMMPS library compiled with the
|
||
traditional make build using <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">mode=shared</span> <span class="pre">serial</span></code> becomes:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>gcc<span class="w"> </span>-c<span class="w"> </span>-O<span class="w"> </span>-I<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/src<span class="w"> </span>-caller.c
|
||
g++<span class="w"> </span>-o<span class="w"> </span><span class="nb">caller</span><span class="w"> </span>caller.o<span class="w"> </span>-L<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/src<span class="w"> </span>-llammps_serial
|
||
</pre></div>
|
||
</div>
|
||
</div></div>
|
||
<section id="locating-liblammps-so-at-runtime">
|
||
<h3>Locating liblammps.so at runtime<a class="headerlink" href="#locating-liblammps-so-at-runtime" title="Link to this heading"></a></h3>
|
||
<p>Unlike with a static link, now the <code class="docutils literal notranslate"><span class="pre">liblammps.so</span></code> file is required at
|
||
runtime and needs to be in a folder, where the shared linker program of
|
||
the operating system can find it. This would be either a folder like
|
||
<code class="docutils literal notranslate"><span class="pre">/usr/local/lib64</span></code> or <code class="docutils literal notranslate"><span class="pre">${HOME}/.local/lib64</span></code> or a folder pointed to
|
||
by the <code class="docutils literal notranslate"><span class="pre">LD_LIBRARY_PATH</span></code> environment variable. You can type</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>printenv<span class="w"> </span>LD_LIBRARY_PATH
|
||
</pre></div>
|
||
</div>
|
||
<p>to see what directories are in that list.</p>
|
||
<p>Or you can add the LAMMPS src directory or the directory you performed a
|
||
CMake style build in to your <code class="docutils literal notranslate"><span class="pre">LD_LIBRARY_PATH</span></code> environment variable,
|
||
so that the current version of the shared library is always available to
|
||
programs that use it.</p>
|
||
<p>For the Bourne or Korn shells (/bin/sh, /bin/ksh, /bin/bash etc.), you
|
||
would add something like this to your <code class="docutils literal notranslate"><span class="pre">${HOME}/.profile</span></code> file:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>LD_LIBRARY_PATH<span class="w"> </span><span class="si">${</span><span class="nv">LD_LIBRARY_PATH</span><span class="p">-/usr/lib64</span><span class="si">}</span>:<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/lammps/src
|
||
<span class="nb">export</span><span class="w"> </span>LD_LIBRARY_PATH
|
||
</pre></div>
|
||
</div>
|
||
<p>For the csh or tcsh shells, you would equivalently add something like this
|
||
to your <code class="docutils literal notranslate"><span class="pre">${HOME}/.cshrc</span></code> file:</p>
|
||
<div class="highlight-csh notranslate"><div class="highlight"><pre><span></span><span class="nb">setenv </span>LD_LIBRARY_PATH <span class="k">${</span><span class="nv">LD_LIBRARY_PATH</span><span class="k">}</span>:<span class="k">${</span><span class="nv">HOME</span><span class="k">}</span>/lammps/src
|
||
</pre></div>
|
||
</div>
|
||
<p>You can verify whether all required shared libraries are found with the
|
||
<code class="docutils literal notranslate"><span class="pre">ldd</span></code> tool. Example:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span>/home/user/lammps/src<span class="w"> </span>ldd<span class="w"> </span><span class="nb">caller</span>
|
||
<span class="w"> </span>linux-vdso.so.1<span class="w"> </span><span class="o">(</span>0x00007ffe729e0000<span class="o">)</span>
|
||
<span class="w"> </span>liblammps.so<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/home/user/lammps/src/liblammps.so<span class="w"> </span><span class="o">(</span>0x00007fc91bb9e000<span class="o">)</span>
|
||
<span class="w"> </span>libstdc++.so.6<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/lib64/libstdc++.so.6<span class="w"> </span><span class="o">(</span>0x00007fc91b984000<span class="o">)</span>
|
||
<span class="w"> </span>libm.so.6<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/lib64/libm.so.6<span class="w"> </span><span class="o">(</span>0x00007fc91b83e000<span class="o">)</span>
|
||
<span class="w"> </span>libgcc_s.so.1<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/lib64/libgcc_s.so.1<span class="w"> </span><span class="o">(</span>0x00007fc91b824000<span class="o">)</span>
|
||
<span class="w"> </span>libc.so.6<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/lib64/libc.so.6<span class="w"> </span><span class="o">(</span>0x00007fc91b65b000<span class="o">)</span>
|
||
<span class="w"> </span>/lib64/ld-linux-x86-64.so.2<span class="w"> </span><span class="o">(</span>0x00007fc91c094000<span class="o">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>If a required library is missing, you would get a ‘not found’ entry:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>ldd<span class="w"> </span><span class="nb">caller</span>
|
||
<span class="w"> </span>linux-vdso.so.1<span class="w"> </span><span class="o">(</span>0x00007ffd672fe000<span class="o">)</span>
|
||
<span class="w"> </span>liblammps.so<span class="w"> </span><span class="o">=</span>><span class="w"> </span>not<span class="w"> </span>found
|
||
<span class="w"> </span>libstdc++.so.6<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/usr/lib64/libstdc++.so.6<span class="w"> </span><span class="o">(</span>0x00007fb7c7e86000<span class="o">)</span>
|
||
<span class="w"> </span>libm.so.6<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/usr/lib64/libm.so.6<span class="w"> </span><span class="o">(</span>0x00007fb7c7d40000<span class="o">)</span>
|
||
<span class="w"> </span>libgcc_s.so.1<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/usr/lib64/libgcc_s.so.1<span class="w"> </span><span class="o">(</span>0x00007fb7c7d26000<span class="o">)</span>
|
||
<span class="w"> </span>libc.so.6<span class="w"> </span><span class="o">=</span>><span class="w"> </span>/usr/lib64/libc.so.6<span class="w"> </span><span class="o">(</span>0x00007fb7c7b5d000<span class="o">)</span>
|
||
<span class="w"> </span>/lib64/ld-linux-x86-64.so.2<span class="w"> </span><span class="o">(</span>0x00007fb7c80a2000<span class="o">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
|
||
<a href="Build_make.html" class="btn btn-neutral float-left" title="3.2. Build LAMMPS with make" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
||
<a href="Build_basics.html" class="btn btn-neutral float-right" title="3.4. Basic build options" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
||
</div>
|
||
|
||
<hr/>
|
||
|
||
<div role="contentinfo">
|
||
<p>© Copyright 2003-2025 Sandia Corporation.</p>
|
||
</div>
|
||
|
||
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
|
||
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
|
||
provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
||
|
||
|
||
</footer>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
<script>
|
||
jQuery(function () {
|
||
SphinxRtdTheme.Navigation.enable(false);
|
||
});
|
||
</script>
|
||
|
||
</body>
|
||
</html> |