Skip to content

Instantly share code, notes, and snippets.

@allexiusw
Last active November 15, 2019 21:56
Show Gist options
  • Save allexiusw/8bdf7c45e273f0ccae28d24345e88756 to your computer and use it in GitHub Desktop.
Save allexiusw/8bdf7c45e273f0ccae28d24345e88756 to your computer and use it in GitHub Desktop.
Proof of concept Shared libraries on Linux
nano sqrttest.c
/* sqrttest.c */
#include <math.h>
#include <stdio.h>
int main(void)
{
printf("%g\n", sin(3.141592654/2.0));
return 0;
}
#save the script
#Now compile it without shared libraries
gcc -static sqrttest.c -lm -o sqrttest-static
#run the binary
./sqrttest-static
#check the size of static binary
ls -lh sqrttest-static
#Compile the program with shared libraries
gcc sqrttest.c -lm -o sqrttest-dynamic
#run the binary
./sqrttest-dynamic
#check the size of binary with dynamic libraries
ls -lh sqrttest-dynamic
#Let's conclude that Shared Libraries are very important thing
#in optimize an application and manage code efficiently.
#check shared libraries used by a binary
ldd sqrttest-dynamic
ldd sqrttest-static
#end of poc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment