How to add 3rd party libraries to MinGW?

人走茶凉 提交于 2020-01-02 01:07:09

问题


I've just set up MinGW environment following this post

But how to add 3rd party libraries to it?


回答1:


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




回答2:


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.




回答3:


I just went through figuring this out myself. I strongly recommend reading the linking howtos on the MinGW webpage. Read them carefully as there is quite a lot to take in. They are quite thorough though so it's well worth your time.

There are essentially two ways of doing things. First, you can just regard MinGW as a compiler, because that's what it is, and invoke it from cmd.exe (the command prompt) or an IDE. The other way to do it is to use MSYS which is basically a Unix style shell that you can run on Windows to use Unix style build tools like configure and make.

For either of these you really have to read the howto I linked above to understand how dependency paths are being searched. I hesitate to explain it here as it is already explained in the howtos and duplicating that information is not a good idea. If you have specific questions after reading them I'd be happy to offer more help.



来源:https://stackoverflow.com/questions/1985764/how-to-add-3rd-party-libraries-to-mingw

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!