本文介绍了如何在MinWG上与gcc链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

此语法不正确吗?

C:\Users\Brett\Compilers>gcc -I MinGW\include -l MinGW\lib\libgdi32.a -o hello
    world helloworld.c

目录都很好,我会以错误的顺序包含或链接吗?

The directory's are all fine, I mist be including and linking in the wrong order or something?

以下是输出:

c:/users/Brett/compilers/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw
2/bin/ld.exe: cannot find -lMinGW\lib\libgdi32.a
collect2: ld returned 1 exit status

推荐答案

-l开关的语法是没有lib前缀且没有扩展名的库名.如果找不到,则应使用-L选项指定目录.所以我会写:

The syntax for -l switch is the library name without lib prefix and without the extension. If it cannot be found, it's directory should be given with -L option. So I would write:

gcc -I MinGW\include -L MinGW\lib -lgdi32 -o helloworld helloworld.c

也许不需要-L,也许您还需要-mwindows告诉链接器您想要Windows应用程序.要明确指定库文件,请给其不带任何字母的选项,例如:

Maybe -L is not needed, maybe you also need -mwindows to tell the linker you want windows app. To specify a library file explicitly, give it without any letter option, like this:

gcc -I MinGW\include MinGW\lib\libgdi32.a -o helloworld helloworld.c

以下是gcc参考:链接选项.

这篇关于如何在MinWG上与gcc链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:44