MinGW无法编译hello world

时间:2013-05-01 05:46:52

标签: windows gcc mingw

我刚刚使用默认的GUI安装程序安装了MSYS和MinGW,检查了所有复选框。然后我做了一个简单的hello world程序,并尝试在MSYS命令行上编译它。这就是:

$ gcc test.c
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: 
   cannot find -lshell32
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: 
   cannot find -luser32
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: 
   cannot find -lkernel32
collect2: ld returned 1 exit status

带有详细标记:

$ gcc -v test.c
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-mtune=i386' '-march=i386'
 c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/cc1.exe -quiet -v -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.6.2/ test.c -quiet -dumpbase test.c -mtune=i386 -march=i386 -auxbase test -version -o C:\DOCUME~1\Owner\LOCALS~1\Temp\ccz34YZu.s
GNU C (GCC) version 4.6.2 (mingw32)
    compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=82 --param ggc-min-heapsize=98237
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/include"
ignoring duplicate directory "/mingw/lib/gcc/mingw32/4.6.2/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include-fixed
End of search list.
GNU C (GCC) version 4.6.2 (mingw32)
    compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=82 --param ggc-min-heapsize=98237
Compiler executable checksum: c20aed7c018482d7b62efcd5dcab2a9d
COLLECT_GCC_OPTIONS='-v' '-mtune=i386' '-march=i386'
 c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/as.exe -o C:\DOCUME~1\Owner\LOCALS~1\Temp\ccgcJLdQ.o C:\DOCUME~1\Owner\LOCALS~1\Temp\ccz34YZu.s
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.2/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../;/mingw/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=i386' '-march=i386'
 c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/collect2.exe -Bdynamic c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtbegin.o -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../.. -L/mingw/lib C:\DOCUME~1\Owner\LOCALS~1\Temp\ccgcJLdQ.o -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtend.o
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lshell32
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -luser32
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lkernel32
collect2: ld returned 1 exit status

我做错了什么?我是否需要Microsoft开发库,如果我这样做,我在哪里可以获得它们?

1 个答案:

答案 0 :(得分:0)

尝试检查安装mingw和MSYS时是否正确设置了所有环境变量。