<li>Link edition (Linking): produces executables/libraries from .o files and libraries with '-l' option</li>
<li>At compilation, g++ searches through standard paths (such as /usr/lib) </li>
<li>Extend the list can be done with the option '-L' <divclass="highlight"><pre><span></span>> g++ file1.o file2.o -L/some_path/ -lmylib -o <spanclass="nb">exec</span>
<li>A <ahref="https://en.wikipedia.org/wiki/Static_library">Static libraries</a> is a set of routines, external functions and variables which are resolved by linker/binder to produce a stand-alone executable. </li>
<li>Generally with extension "libXXXX.a" (e.g. /usr/lib/x86_64-linux-gnu/libm.a). </li>
<li>The final executable statically linked includes all the libraries (big executable file)</li>
<li><ahref="https://en.wikipedia.org/wiki/Library_(computing">Dynamic/Shared libraries</a>#Shared_libraries) are loaded on demand by executables. </li>
<li>Shared libraries can be statically linked or dynamically loaded.</li>
<li>libXXX.so (or libXXX.dll on windows). e.g. /usr/lib/x86_64-linux-gnu/libm.so</li>
<h2id="Finding-a-symbol-from-a-list-of-files">Finding a symbol from a list of files<aclass="anchor-link"href="#Finding-a-symbol-from-a-list-of-files">¶</a></h2>
<h2id="Creating-an-executable">Creating an executable<aclass="anchor-link"href="#Creating-an-executable">¶</a></h2><divclass="highlight"><pre><span></span><spanclass="nb">cmake_minimum_required</span><spanclass="p">(</span><spanclass="s">VERSION</span><spanclass="s">3.1</span><spanclass="p">)</span>
<h2id="Adding-paths-to-the-include-search-list">Adding paths to the include search list<aclass="anchor-link"href="#Adding-paths-to-the-include-search-list">¶</a></h2><divclass="highlight"><pre><span></span><spanclass="nb">include_directories</span><spanclass="p">(</span><spanclass="s">'/my_preferred_path'</span><spanclass="p">)</span>
<h2id="Adding-an-external-library">Adding an external library<aclass="anchor-link"href="#Adding-an-external-library">¶</a></h2><divclass="highlight"><pre><span></span><spanclass="nb">add_executable</span><spanclass="p">(</span><spanclass="s">exe</span><spanclass="s">file1.cc</span><spanclass="s">file2.cc</span><spanclass="p">)</span>
<h2id="Creating-a-library">Creating a library<aclass="anchor-link"href="#Creating-a-library">¶</a></h2><divclass="highlight"><pre><span></span><spanclass="nb">add_library</span><spanclass="p">(</span><spanclass="s">mylib</span><spanclass="s">file1.cc</span><spanclass="s">file2.cc</span><spanclass="p">)</span>
<h2id="Making-options">Making options<aclass="anchor-link"href="#Making-options">¶</a></h2><divclass="highlight"><pre><span></span><spanclass="c"># should we use our own math functions?</span>
<divclass="highlight"><pre><span></span><spanclass="nb">set</span><spanclass="p">(</span><spanclass="s">GSL_LIBRARY_PATH</span><spanclass="s">CACHE</span><spanclass="s">PATH</span><spanclass="s2">"library where to search libgsl"</span><spanclass="p">)</span>
<divclass="highlight"><pre><span></span><spanclass="nb">set</span><spanclass="p">(</span><spanclass="s">GSL_INCLUDE_PATH</span><spanclass="s">CACHE</span><spanclass="s">PATH</span><spanclass="s2">"path where to search gsl include files"</span><spanclass="p">)</span>