I have been afflicted by the way to include a custom library since I started learning C language. I had no way to use custom libraries, such as strlib.h (which is not a standard ANSI C library nor extended library), in a program source. I have been googling the way for several days but still can’t find any answer (I finally know the way after thousands of trials).
The reason for why I can’t find any answer may be just because it’s too fundamental, which is assumed to be “common sense". Then, how did I know the way to include the library?
As custom libraries are included in the program source, when the compiler compiles it and sees the line #include “testing.h", it would certainly (obviously?) search for the library in the same folder of the program source file. Therefore, if I put the library package in the same folder, the compiler will find it. Though this seems to be very easy to understand, but the wrong methods sounds reasonable too.
The wrong method:
For a C language noob, like me, I searched the folder, in which the stdio.h library is located (In exact, it’s located in the \include folder inside the folder of the compiler (such as MinGW)). And, it seems to be quite reasonable to put a custom library header file there too. Then, how about the file of library implementation? In the same folder, I can’t find any c source file (implementation) of stdio.h.
Thus, this way just sounds reasonable, but indeed, not.
The correct method:
As I have said in the introduction part, the library package (implementation file (.c) and header file (.h)) and the programme source file has to be put in the same folder.
You use double quotes for custom libraries (I think this is the way to tell the compiler that, the library not located in the \include folder). For example: #include “strlib.h"