gcc -shared -Wl,-soname,your_soname \
        -o library_name file_list library_list

    Here’s an example, which creates two object files (a.o and b.o) and then creates a shared library that contains both of them. Note that this compilation includes debugging information (-g) and will generate warnings (-Wall), which aren’t required for shared libraries but are recommended. The compilation generates object files (using -c), and includes the required -fPIC option:

    gcc -fPIC -g -c -Wall a.c
    gcc -fPIC -g -c -Wall b.c
    
    gcc -shared -Wl,-soname,libmystuff.so.1 -o libmystuff.so.1.0.1 a.o b.o -lc

    Leave a Reply