I want to create an abstract linked-list implementation (having general operations to createList, destroy, addNode, deleteNode, etc.). How do I make these functions available to anyone who is using the OS? (I am using Ubuntu.)
I can have the declaration of a function:
In add.h:
int add(int a,int b); /* add.h having the declaration */
In add.c:
#include "add.h"
int add(int a,int b) /* add.c having only definition */
{
return (a+b);
}
In main.c:
#include<stdio.h>
#include"add.h"
int main()
{
//use add() here
}
How do I have the API set up in the Linux environment such that the implementation in add.c is hidden from the user of the API? I don’t want to force the users of the API to copy the add.h file in their working directory; I’d rather have some way to install it to the Linux environment.
If the solution of bobah is not good enough, because you don’t want to specify the path where your sources are currently, when you use the API, you can install the library into the system directories (/usr/local/lib, /usr/local/include and so on). Then, you wont need
-Iand-L. You’ll still need-l.You’ll need admin rights for that (be root, or use sudo).
Consider using the “install” command.
And “libtool”, if you want to build a shared object of your library.
And the autotools (autoconf and automake).
If you mean really anyone, and not just anyone on your computer, with this
then you’ll also need to build a source or binary package. And convince the Ubuntu maintainers to include it into their repository. Which will probably be difficult for yet another linked list library.