top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How can I create my own library in C?

+1 vote

I want to build my own library in C, can someone help me with this?

posted May 22, 2014 by Atul Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

A library is shipped with object module of library and header file. User links the object module and use the header file.

This object module can be static library or shared library (dll on Windows). Static library is similar to C program except that it does not have main function. You can use tools such as ld, ar to generate the library from object file (on Windows, use LIBTOOL).

answer May 22, 2014 by Devender Mishra
+1 vote

Assuming that you are using gcc and Linux or any unix based environment

To create a Library of code you need to do the following:
(1) Create an INTERFACE to your library: mylib.h
(2) Create an IMPLEMENTATION of your library: mylib.c
(3) Create a LIBRARY OBJECT FILE that can be linked with programs that want to use our library code or create a SHARED OBJECT FILE from many .o files that can be linked with programs that want to use your library code

 gcc -o mylib.o -c mylib.c
 gcc -shared -o  mylib.o  (for .a -shared is not required)

(4) USE the library in other C code: (a) #include "mylib.h" (b) link in the libary code into binary file
(5) Set LD_LIBRARY_PATH environment variable for finding shared objects in non-standard locations at runtime.

If you still any have any query please feel free to comment...

answer May 22, 2014 by Santosh Prasad
Similar Questions
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.