Creating a library

This is an example of creating your own external library to use that has some status variables only available locally to it.

It is written as an idea to create your own logging library on.

Main code with example commands. It also contains the inclusion of the header file, which will tell the compiler what functions are available and help the IDE use them.

Library header

Add all the content that you need for the header. This is what will be shown to “the rest of the world” as things that are available in your library. It can also be called an interface in a way.

Library code

This is where you will implement your code. All the functionality that you promised in the header must be available here.

You will also see global variables here. Usually we try to avoid these, but that’s not always necessary. There are 2 things to note here. First, it will avoid us having to carry some general information around, that should be available for every part of the program. Secondly, these are localized to the function – we are not interacting with it outside of the predefined set of functions. You cannot alter the values outside of this file.

To compile the project:

gcc -Wall -Wextra -Wconversion demo.c writer.c -o demo