I am fairly new to C and I am trying to include a external library without using any IDE, only text-editor and the minGW compi
You have two parts to take care of:
In compilation, when you transform source files in object files, your compiler must know what are the functions provided by the external library.
You could declare each function you use or you can include the library header file(s) in your code:
#incude <library_file.h>
It's not enough, you will have to tell your compiler where it can find this file:
-I<path_to_lib_folder>
with gcc
/I<path_to_lib_folder>
with cl
(the visual studio compiler)In linking process, you put the object and library files together to construct an executable file.
You need to tell the linker
You tell the linker what files to use with the -l
options, for instance, -lfoo
will tell it to search for the libfoo.so lib
Note: with cl
you can tell specify which library to use directly in your source code with #pragma comment (lib, "libfoo.lib")
Add you specify where with:
-L<path_to_lib_folder>
with gcc
/LIBPATH:<path_to_lib_folder>
with link
(the visual studio linker)You can also use dynamic linking, but let's start with the first step.