Static and Dynamic Library
Combine the files of the objects into a single static library/archive using the command:
ar rcs bin/static/libadd.a bin/static/add.o bin/static/answer.oLink the static main.o with the library using the command:
gcc bin/main.o -Lbin/static –ladd -o bin/statically-linkedFor a shared library in GCC ending with .so instead of .a, use the command:
gcc -shared bin/shared/add.o bin/shared/answer.o -o bin/shared/libadd.soConnect dynamically to the shared library using the command:
gcc bin/main.o -Lbin/shared -ladd -o bin/use-shared-libraryMove the shared library to the default location:
sudo mv bin/shared/libadd.so /usr/lib
sudo chmod u=rwx,go=rx /usr/lib/libadd.soUse the shared library through LD_LIBRARY_PATH:
LD_LIBRARY_PATH=$(pwd)/bin/shared bin/use-shared-libraryLast updated
Was this helpful?