I've just set up MinGW environment following this post
But how to add 3rd party libraries to it?
I've just set up MinGW environment following this post
But how to add 3rd party libraries to it?
No different from any other system using gcc
and now use your new library with proper -Lfoo/bar -lfoobar
switches.
I recommend the MSys system around MinGW in order to do all this.
A library consists of two main components - the C header files and the compiled object code archive. GCC has a bewildering array of ways of specifying these things, but let's say you are using a library foo.a
which lives in the relative directory path foo/lib
, and a header foo.h
which lives in foo/inc
. Your own C code lives in main.c
and looks like this:
#include "foo.h"
int main() {
return FooFunc(); // call function in foo.a
}
To compile this, you could use the command line:
gcc main.c -Ifoo/inc foo/lib/foo.a -o main.exe
the -I flag adds to the path searched for headers. You can also add to the lib path, but then things start to get complicated :-)