How to get a .so file after compiling a c-program?

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.

+4
source share
2 answers

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
+4
source

, .o, -fPIC, . , , (: , )

gcc, , :

gcc -shared -o library_name.so a.o b.o
+4

All Articles