0

When I compile c++ and c files together with the following command:

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

error occurs:

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

And in fact,the collect2.exe exists in the correct directory. I've tried all the solutions provided online, but no one worked.(etc. set/clear environment values,try other versions of mingw32...) The only reason I could think up is that the g++.exe uses / in directories, and windows uses \ instead. So is there any other solutions for the error?

shijy
  • 21
  • 3

2 Answers2

1

LeafFourth identified this for me in this posting: 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.

How I resolved this.

a. add -v to the compile command:
c:\Programs\gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf\bin\arm-none-linux-gnueabihf-gcc test5.c -o newlybuiltFile.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.
    

b. I verified all of the files listed - checked the path and saw their existance. NOTE: initially, I did not really look at the file size (I typically do not display it)

c. note that the *.DLL files also call other functions/libraries. So you may not be seeing everything. this could be a really big task to verify all files.

d. I finally noticed that my primary bin files did not install properly. see image.

clearly not a good install

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

improved install for my primary bin executables

e. solution was to re-install the MinGW tools. The simple compile now works properly.

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.

shijy
  • 21
  • 3