Examples of static and Dynamic linking of libraries in C, plus how to create such libraries.
- The examples container here strictly use GCC as the compiler. For *NIX use the general GNU distribution of GCC, and for Windows, use MinGW-w64.
- The
-s
flag is used extensively throughout the examples in this repository, but it must be noted that it is totally optional and used here only to reduce the output filesize by removing all symbol table and relocation information.
For different types of linking, I have made:
static
: Static Linking.dynamic
: Dynamic Linking.
Within each, I have added examples for *NIX and Windows:
nix
: *NIX.win
: Windows.
Each of the two contains a Makefile
with a simple
instruction to clean all files built.
Within each of those two, I have created:
library
: The library source code andMakefile
.usage
: A simple usage of the same, with theMakefile
.
The Makefile
s within those two directories contain a default build
instruction to compile the code, and
a clean
instruction to clean all files built
.
- The 'link' being referred to in 'symbolic link' and the one in 'static/dynamic link' are completely unrelated.
- The source code used for the sample library and the
testing file is container inside
src
in the repository's root. The source files are symbolically linked into the desired places, so please ensure you have enabled symbolic links in Git before cloning.git config --global core.symlinks true
- In Windows systems, this would also require you to clone via a console with administrative priviledges, because creating symbolic links would require them.
- Git won't warn you if you clone without giving
administrative privileges: It will simply create copies
of files instead of symbolcally linking them,
even if you have the global
core.symlinks
set totrue
. This would still allow everything to work, but if you need to edit, for example,main.c
, the changes won't reflect everywheremain.c
is being used. - To enforce symbolic links while creating the clone,
use
You don't need to enforce this if you are running the command-line with administrative privileges.
git clone -c core.symlinks=true https://url/to/repo
- If you have Developer Mode enabled in Windows 10, you won't need to grant administrative privileges for using symbolic links.