gcc MinGW无法编译hello world

ggazkfy8  于 2022-11-13  发布在  其他
关注(0)|答案(2)|浏览(169)

我只是使用默认的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

我做错了什么?我需要微软开发库吗?如果需要,在哪里可以得到它们?

eit6fx6z

eit6fx6z1#

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

brjng4g3

brjng4g32#

环境变量try path和mingw/bin的add browse中存在错误

相关问题