hi,
what is the difference between static and shared library how do we create them and what is the extension used for both of
hi,
what is the difference between static and shared library how do we create them and what is the extension used for both of
The short answers from , and cover the basics. Missing from the thread are practical build steps, runtime/versioning notes, common pitfalls and quick checks you can use right away. Below are concise, practical examples and troubleshooting tips that fill those gaps.
Common build steps (examples for GNU toolchain):
gcc -c foo.c -o foo.o
ar rcs libfoo.a foo.o gcc -fPIC -c foo.c -o foo.o
gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0.0 foo.o
ln -s libfoo.so.1.0.0 libfoo.so.1
ln -s libfoo.so.1 libfoo.so Link an executable against the shared lib and embed an rpath so it finds the library next to the binary:
gcc main.c -L. -lfoo -Wl,-rpath,'$ORIGIN' -o app Quick runtime checks and troubleshooting
ldd app to list dynamic dependencies (do not run on untrusted binaries; prefer readelf -d or objdump -p there). nm -g, objdump -T or readelf -s to inspect exported symbols and diagnose unresolved references. LD_LIBRARY_PATH temporarily or add the directory to the system cache with ldconfig, or use an embedded rpath (-Wl,-rpath). cl /LD foo.c builds a DLL and import LIB; MinGW can produce a DLL and an import lib with -Wl,--out-implib,libfoo.a.Caveats and best practices
-fPIC) on platforms that require it. extern "C" or a stable C wrapper. These steps should make it straightforward to create, test and deploy libraries while avoiding the common pitfalls not covered earlier in the thread.
Jump to Post— Narue 5,707Every different program that uses a static library has its own copy of the library built in. A shared library only has one copy and every program that uses it just references that copy. How you create them depends on the tool you're using, and how they're named depends on …
Every different program that uses a static library has its own copy of the library built in. A shared library only has one copy and every program that uses it just references that copy. How you create them depends on the tool you're using, and how they're named depends on the platform. For example, on Windows it might be *.lib versus *.dll. On Linux it might be *.a versus *.so.
And it gets a little more complicated because there are *nix compilers that have been ported to MS-Windows os, and consequently still use *.a library extensions. Dev-C++ is one such compiler. So for libraries the extension depends on the compiler.
Not that it matters too much. I think that .lib files are the same format as .a files these days.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.