I have used a lot of shared libraries. Then thought of building one with gcc. Before building, I thought that it will be difficult thing to do. After creating one, I felt like “Is that all we have to do ?????”. I followed the steps:

  • Created a function in a file (myshared.c) without a main() function.
  • Compiled it with -enable-shared option and renamed to libmyshared.so. Thatz all. I have created a shared library.
  • For using it, I updated the LD_LIBRARY_PATH to the location where the .so is present. The other option is to run ldconfig.
  • To use it, I used gcc -lmyshared myfile.c.
    • -l option searches for libmyshared.so in the library path.
    • myfile.c is the one that uses the function that I have created in the myshared.c
  • Done…..