Static and dynamic C/C++ compilation.
This will embed the dependencies in the executable, and changes to the dependencies will require the client application to be built again.
g++ -c shared.cpp
ar -cvq shared.a shared.o
g++ main.cpp shared.a -o main.outTo run the applicatoin:
./main.outA dynamic dependency (shared / linked library) allows the dependency to be updated without changes to the client code, giving that the interface between the programs remain compatible.
g++ -c -fPIC shared.cpp
g++ -shared shared.o -o libshared.so
g++ -L. main.cpp -lshared -o main.outTo run the application:
./main.outThis will print Hello V1! from the shared library.
Now to demonstrate the effect of a dynamic update compile the V2:
g++ -c -fPIC sharedv2.cpp -o shared.o
g++ -shared shared.o -o libshared.soThis will update the library and running the main program will output Hello V2! as a result:
# Hello V2!
./main.out