本文介绍了如何在MinGW中添加第三方库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚按照

但是如何向其中添加第三方库?

But how to add 3rd party libraries to it?

推荐答案

一个库由两个主要组件组成-C头文件和已编译的目标代码档案. GCC有各种各样令人困惑的方法来指定这些内容,但是假设您使用的是位于相对目录路径foo/lib中的库foo.a和位于foo/inc中的标头foo.h.您自己的C代码位于main.c中,如下所示:

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

-I标志将添加到搜索标头的路径中.您也可以添加到lib路径,但是事情开始变得复杂:-)

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

这篇关于如何在MinGW中添加第三方库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 23:05