将库与minGW链接 [英] Linking libraries with minGW

查看:59
本文介绍了将库与minGW链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:Windows 7;MinGW(GCC)版本4.8.1;c ++

I am using: Windows 7; MinGW (GCC) version 4.8.1; c++

我有几个自己的构建库,它们链接到一个可执行文件.一个简单的示例,其中包含一个要链接的库: libFolder \ libforms.a

I have several own build libraries which links together to an executable. A simple example with one library to link: libFolder\libforms.a

A) g ++ -o main \ theApp.exe main \ main.o -LlibFolder \ -lforms

B) g ++ -o main \ theApp.exe main \ main.o libFolder \ libforms.a

两者都生成相同的可执行文件.

Both generate the same executable.

  • 这两种让gcc知道什么的方法有什么区别库链接?
  • 是否有任何缺点或B上不能采取行动?

推荐答案

这两个命令之间的区别在于,在第一个命令中,您添加了链接器要搜索的路径,并告诉链接器搜索表单.库,然后在第二个命令中告诉链接程序无需搜索即可直接链接到特定库.

The difference between the two commands is that in the first you add a path for the linker to search and you tell the linker to search for the forms library in the search paths, and in the second command you tell the linker to link directly with a specific library without needing to search for it.

两个命令均能很好地工作,并且会产生相同的结果.您选择哪一个完全取决于您.第二个变体的唯一缺点是,如果必须链接多个库,则必须多次提供相同的路径,而不必与第一个变体相关.

Both commands works equally well, and will produce the same result. Which one you choose is totally up to you. The only drawback to the second variant is if you must link with multiple libraries, as then you must provide the same path multiple times, which you don't have to do with the first variant.

这篇关于将库与minGW链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆