tags:

views:

190

answers:

2

I've just set up MinGW environment following this post

But how to add 3rd party libraries to it?

+1  A: 

No different from any other system using gcc

  • get the sources
  • untar
  • run configure -- this may require a tweak or two
  • make
  • make install

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.

Dirk Eddelbuettel
Oh,I forgot to mention that I'm using windows XP,can you be more specific about the details?
You need a book (or web tutorial) about code development with Unix tools. There is nothing that specific to Windows XP here --- apart from the fact that you are trying to learn a workflow that is not common on Windows. You are doing the right thing here, but you more or less need to know how it works on Linux/Unix to infer how it is done on XP. Just find a decent tutorial somewhere...
Dirk Eddelbuettel
+2  A: 

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 :-)

anon
+1,it's helpful!But can you make it more general?Say if I want to include 2 libraries from two different directories.BTW,seems not every library consists of *.h and *.a,at least I see only*.a and *.o under MinGW/lib?
To specify more include paths, use more -I flags, to specify more libraries, specify them on the command line. At the end of the day, SO is not a tutorial site - read the GCC manual and posibly a book, such as http://www.network-theory.co.uk/gcc/intro.
anon