0

当我使用以下命令编译 c++ 和 c 文件时:

g++ io.c *.cpp -o main  -D__STDC_FORMAT_MACROS

发生错误:

g++.exe: fatal error:cannot execute ‘C:/TDM-GCC-32/bin/../libexec/gcc/mingw32/9.2.0/collect2.exe’: CreateProcess: No such file or directory

事实上,它collect2.exe存在于正确的目录中。我已经尝试了在线提供的所有解决方案,但没有一个有效。(等设置/清除环境值,尝试其他版本的 mingw32 ......)我能想到的唯一原因是目录中的g++.exe用途/和 windows 使用\反而。那么这个错误还有其他解决方案吗?

4

2 回答 2

1

LeafFourth 在这篇文章中为我确定了这一点: https ://github.com/kriscross07/atom-gpp-compiler/issues/26

LeafFourth commented on Mar 23
I have experienced this problem before. The root cause is an exe file was unziped failed with the size zero. I tried another unzip tool to solved it.

For the problem, to know how it happened is important:
CreateProcess is a API to create a process, so the error indicated that the image file used to create the process may not exist.

How to solve it:
Add "-v" flags to run gcc/g++ to compile and then, the verbose log shows. We can find which file not exists. If nothing goes wrong, we can just run the last command in the verbose log with flag "-v" to continue to check recursively.

我是如何解决这个问题的。

一个。将 -v 添加到编译命令:
c:\Programs\gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf\bin\arm-none-linux-gnueabihf-gcc test5.c - o newbuiltFile.out -v

Note: test5.c was a simple main() with no functions.

output was messy, finally ending in 

    c:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../libexec/gcc/arm-none-linux-gnueabihf/9.2.1/collect2.exe -plugin c:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../libexec/gcc/arm-none-linux-gnueabihf/9.2.1/liblto_plugin-0.dll -plugin-opt=c:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../libexec/gcc/arm-none-linux-gnueabihf/9.2.1/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\pops\AppData\Local\Temp\ccTNEjZv.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --sysroot=c:\programs\gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf\bin\../arm-none-linux-gnueabihf/libc --eh-frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X -m armelf_linux_eabi -o test5.out c:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../arm-none-linux-gnueabihf/libc/usr/lib/crt1.o c:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../arm-none-linux-gnueabihf/libc/usr/lib/crti.o c:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/crtbegin.o -Lc:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1 -Lc:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../lib/gcc -Lc:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/../../../../arm-none-linux-gnueabihf/lib -Lc:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../arm-none-linux-gnueabihf/libc/lib -Lc:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../arm-none-linux-gnueabihf/libc/usr/lib C:\Users\pops\AppData\Local\Temp\ccjF1go9.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state c:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/crtend.o c:/programs/gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../arm-none-linux-gnueabihf/libc/usr/lib/crtn.o
    collect2.exe: fatal error: CreateProcess: No such file or directory
    compilation terminated.
    

湾。我验证了所有列出的文件 - 检查了路径并看到了它们的存在。注意:最初,我并没有真正查看文件大小(我通常不显示它)

C。请注意,*.DLL 文件还调用其他函数/库。所以你可能没有看到一切。验证所有文件可能是一项非常艰巨的任务。

d。我终于注意到我的主 bin 文件没有正确安装。见图片。

显然不是一个好的安装

>   proper install should have files with size > 0 Kbytes.

改进了我的主要 bin 可执行文件的安装

e. 解决方案是重新安装 MinGW 工具。简单的编译现在可以正常工作。

于 2020-11-14T01:01:15.197 回答
0

Well, I finally successfully compile the source files with Visual Studio. It's not an answer for this question but it's a way out if no other solutions found.

于 2020-04-28T06:09:13.223 回答