Some notes on linker errors

Linking is the final step of creating an executable by combining all the required functions Functions are usually provided from the compiled source code and from external libraries. Typically, dynamic linking is employed, i.e. external libraries are not included into the executable but will be used only when the program runs. Libraries that are dynamically linked are also called shared libraries. Once share libraries are installed, they can be loaded by every program on the computer. This reduced the size of the executables but can cause problems when a program needs a library (in a certain version) to run.

Linking a shared library is done via the -l option, which is followed by the name of the library without lib but with extension .so (shared object): -lfftw is looking for a file called libfftw.so. The search order is from left to right, i.e. the linker looks at the leftmost file and its requirements and checks every file to the right if it provides the references. stackexchange

If some libraries (references) are missing when
  1. ) linking the executable
  2. ) running the executable
an error appears.

Unfortunately, even on the same system a successful linking operation does not necessary mean that running the executable will be successful as search paths differ. While linking, the order is the following
  1. )
While executing, the order is the following stackexchange
  1. ) LD_LIBRARY_PATH (DYLD_LIBRARY_PATH on Mac OS X)
  2. ) the rpath of the executable
  3. ) standard directories

LIBRARY_PATH is used by gcc before compilation to search for directories containing libraries that need to be linked to your program.

LD_LIBRARY_PATH is used by your program to search for directories containing the libraries after it has been successfully compiled and linked.

EDIT: As pointed below, your libraries can be static or shared. If it is static then the code is copied over into your program and you don't need to search for the library after your program is compiled and linked. If your library is shared then it needs to be dynamically linked to your program and that's when LD_LIBRARY_PATH comes into play.

http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html http://linuxmafia.com/faq/Admin/ld-lib-path.html

-Wl,--as-needed

-- MartinDiehl - 15 Mar 2016
Topic revision: r2 - 16 Mar 2016, MartinDiehl


  • News
26 Mar 2019
DREAM.3D 6.5.119
(released 2019/03/22) comes with a DAMASK export filter
25 Mar 2019
Release of version v2.0.3
21 Jan 2019
DAMASK overview paper finally published with full citation information available
01 Dec 2018
DAMASK overview paper now online
17 Sep 2018
CMCn2018 & DAMASK user meeting to be hosted at Max-Planck-Institut für Eisenforschung
22 May 2018
Release of version v2.0.2
01 Sep 2016
CMCn2016 & DAMASK user meeting to be hosted at Max-Planck-Institut für Eisenforschung
25 Jul 2016
Release of version v2.0.1
08 Mar 2016
Release of version v2.0.0
22 Feb 2016
New webserver up and running
09 Feb 2016
Migrated code repository from Subversion to GitLab
17 Dec 2014
Release of revision 3813
14 May 2014
Release of revision 3108
02 Apr 2014
Release of revision 3062
16 Oct 2013
Release of revision 2689
15 Jul 2013
Release of revision 2555
15 Feb 2013
Release of revision 2174
13 Feb 2013
Doxygen documentation
16 Dec 2012
Powered by MathJax rendering
23 Nov 2012
Release of revision 1955
15 Nov 2012
Release of revision 1924
01 Nov 2012
Updated sidebar
30 Oct 2012
Significant website updates and content extensions


This site is powered by FoswikiCopyright by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding DAMASK? Send feedback
§ Imprint § Data Protection