How can I generate a shared library ( .so) file from a compilation of program C. I wanted to say, if I compile a program in C, I will get a.out. Instead, how can I get a .so file.
.so
a.out
To generate a shared library, you first need to compile your C code with the -fPIC flag (independent of code position).
gcc -c -fPIC file.c -o file.o
This will lead to the creation of an object file (.o), now you take it and create the .so file:
gcc file.o -shared -o lib_file.so
, .o, -fPIC, . , , (: , )
.o
-fPIC
gcc, , :
gcc
gcc -shared -o library_name.so a.o b.o