C Programming – Compile programmes with custom library (#include)

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.

In addition:

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"

對「C Programming – Compile programmes with custom library (#include)」的想法



WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )


您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s