skeeto / w64devkit

Portable C and C++ Development Kit for x64 (and x86) Windows
The Unlicense
2.67k stars 185 forks source link

Compiler unable to compile simple program #49

Closed matsobdev closed 1 year ago

matsobdev commented 1 year ago

I'm on Windows 7 SP1 x64 and something above happens after couple successful compiles from Windows start. Compiling the same again and again and at some point compiler breaks. Or can compile all day and just at the evening it breaks finally. Doesn't matter if using cmake-G "Ninja" or cmake-G "CodeBlocks - MinGW Makefiles" or just configure CLion. Simple gcc works. Example code, Waveshare LCD display - error:

PICO_SDK_PATH is C:/DEV/SDK
PICO platform is rp2040.
Build type is Release
PICO target board is pico.
Using board configuration from C:/DEV/SDK/src/boards/include/boards/pico.h
TinyUSB available at C:/DEV/SDK/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
BTstack available at C:/DEV/SDK/lib/btstack
cyw43-driver available at C:/DEV/SDK/lib/cyw43-driver
Pico W Bluetooth build support available.
lwIP available at C:/DEV/SDK/lib/lwip
mbedtls available at C:/DEV/SDK/lib/mbedtls
-- Configuring done
-- Generating done
-- Build files have been written to: W:/c
[2/446] Performing configure step for 'PioasmBuild'
FAILED: pico-sdk/src/rp2_common/pico_cyw43_driver/pioasm/src/PioasmBuild-stamp/PioasmBuild-configure
cmd.exe /C "cd /D W:\c\pioasm && C:\DEV\CMake\bin\cmake.exe -DCMAKE_MAKE_PROGRAM:FILEPATH=C:/DEV/ARM/bin/ninja.exe -GNinja -CW:/c/pico-sdk/src/rp2_com
mon/pico_cyw43_driver/pioasm/tmp/PioasmBuild-cache-Release.cmake C:/DEV/SDK/tools/pioasm && C:\DEV\CMake\bin\cmake.exe -E touch W:/c/pico-sdk/src/rp2_
common/pico_cyw43_driver/pioasm/src/PioasmBuild-stamp/PioasmBuild-configure"
loading initial cache file W:/c/pico-sdk/src/rp2_common/pico_cyw43_driver/pioasm/tmp/PioasmBuild-cache-Release.cmake
-- The CXX compiler identification is unknown
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/DEV/w64devkit/bin/c++.exe
-- Check for working CXX compiler: C:/DEV/w64devkit/bin/c++.exe - broken
CMake Error at C:/DEV/CMake/share/cmake-3.19/Modules/CMakeTestCXXCompiler.cmake:59 (message):
  The C++ compiler

    "C:/DEV/w64devkit/bin/c++.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: W:/c/pioasm/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/DEV/ARM/bin/ninja.exe cmTC_577fa && [1/2] Building CXX object CMakeFiles\cmTC_577fa.dir\testCXXCompiler.cxx.obj
    FAILED: CMakeFiles/cmTC_577fa.dir/testCXXCompiler.cxx.obj
    C:\DEV\w64devkit\bin\c++.exe    -o CMakeFiles\cmTC_577fa.dir\testCXXCompiler.cxx.obj -c testCXXCompiler.cxx
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!
See also "W:/c/pioasm/CMakeFiles/CMakeOutput.log".
See also "W:/c/pioasm/CMakeFiles/CMakeError.log".

FAILED: elf2uf2/src/ELF2UF2Build-stamp/ELF2UF2Build-configure
cmd.exe /C "cd /D W:\c\elf2uf2 && C:\DEV\CMake\bin\cmake.exe -DCMAKE_MAKE_PROGRAM:FILEPATH=C:/DEV/ARM/bin/ninja.exe -GNinja C:/DEV/SDK/tools/elf2uf2 &
& C:\DEV\CMake\bin\cmake.exe -E touch W:/c/elf2uf2/src/ELF2UF2Build-stamp/ELF2UF2Build-configure"
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/DEV/w64devkit/bin/cc.exe
-- Check for working C compiler: C:/DEV/w64devkit/bin/cc.exe - broken
CMake Error at C:/DEV/CMake/share/cmake-3.19/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "C:/DEV/w64devkit/bin/cc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: W:/c/elf2uf2/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/DEV/ARM/bin/ninja.exe cmTC_61015 && [1/2] Building C object CMakeFiles\cmTC_61015.dir\testCCompiler.c.obj
    FAILED: CMakeFiles/cmTC_61015.dir/testCCompiler.c.obj
    C:\DEV\w64devkit\bin\cc.exe    -o CMakeFiles\cmTC_61015.dir\testCCompiler.c.obj -c testCCompiler.c
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!
See also "W:/c/elf2uf2/CMakeFiles/CMakeOutput.log".
See also "W:/c/elf2uf2/CMakeFiles/CMakeError.log".
ninja: build stopped: subcommand failed.

Error logs below. 1.17, 1.18 the same result. CMakeError.log CMakeError.log From CLion settings:

-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Check for working C compiler: C:/DEV/w64devkit/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: C:/DEV/w64devkit/bin/mingw32-make.exe cmTC_3c64e/fast && 
-- Check for working C compiler: C:/DEV/w64devkit/bin/gcc.exe - broken
CMake Error at C:/DEV/CLion/bin/cmake/win/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "C:/DEV/w64devkit/bin/gcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/Mateusz/AppData/Local/Temp/cmake_check_environment/_build4737323436450688909/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/DEV/w64devkit/bin/mingw32-make.exe cmTC_3c64e/fast && Access violation
    Generator: execution of make failed. Make command was: C:/DEV/w64devkit/bin/mingw32-make.exe cmTC_3c64e/fast && 

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:1 (project)

-- Configuring incomplete, errors occurred!
See also "C:/Users/Mateusz/AppData/Local/Temp/cmake_check_environment/_build4737323436450688909/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Mateusz/AppData/Local/Temp/cmake_check_environment/_build4737323436450688909/CMakeFiles/CMakeError.log".

Error code: 1

Other from https://www.mingw-w64.org/downloads/ work: LLVM-MinGW, MingW-W64-builds, WinLibs.com.

skeeto commented 1 year ago

In all cases CMake is running the "alias" commands (cc, c++, mingw32-make) rather than the tools themselves (gcc, g++, make), and these are failing with "Access violation". The source for these commands is "alias.c" and the access violation likely signifies HeapAlloc() is failing to make the single, tiny (hundreds of bytes) allocation. You said "gcc" works fine when run manually, but what about "cc" or "c++"? Perhaps Windows 7 can get into a state where the Win32 heap functions always fail?

matsobdev commented 1 year ago

After first successful (after Windows restart) compile using CMake cc and c++ ends compiling - faster than when works, simple printf() loop code with no output .exe and no error. gcc still works. Restarting Windows, I can call cc and c++ multiple times with success and after using CMake, it breaks again like before.

skeeto commented 1 year ago

I updated alias.c with better error messages (98a7d85), so at least after the next w64devkit release you'll get a more informative error message when this occurs. It also allocates at a lower level, so maybe the error won't occur at all. I can't imagine how CMake could do anything that would cause HeapAlloc to always fail in other processes.

If you're feeling bold enough to test this new alias.c in your situation, build it like so (in the environment of w64devkit.exe):

$ gcc -g3 -DEXE=gcc.exe -DCMD=gcc -nostartfiles -o $W64DEVKIT_HOME/bin/example alias.c

Then you can invoke GCC via the name "example" just as you can "cc". When "cc" stops working, try compiling something using "example". If that still doesn't work hopefully you'll learn why. Also, this example.exe will be debuggable using the included GDB, so you can at least get a backtrace for me.

matsobdev commented 1 year ago

Funny thing. Just created fresh copy of w64devkit to compile at RAM disk, but doesn't matter I guess other than it is other than system drive/partition. RAM drive w64devkit copy doesn't fail (regular disk other than system drive as well works - talking unmodified, untouched w64devkit). And now example (as well as gcc but we know that already) on system drive works and compiles just fine when cc and c++ are broken after CMake usage.

In the environment of w64devkit.exe I was having some trouble to locate alias.c but in regular Windows cmd.exe with w64devkit as only native compiler in the neighbourhood (system env vars) just worked.

It might be something with Temp dir. Moving it to RAM disk just works and removing RAM disk altogether - so no Temp dir on Windows breaks ARM GCC compiler the same way. So maybe filenames (with paths) too long. That might be an Ninja issue, but happened even before I started using Ninja.

No, no improvement, but just deleting and unzipping w64devkit dir in the same location helps until next one or couple of compiles. Restarting worsk as well as established before.

Unfortunately VirusTotal reports some malicious activity with the original w64devkit zip. Maybe it is a false alarm, but I don't know. Now is undetected, just reissued scan, 12 days ago was some ad injection trojan, but i686 is also 'buggy' at VirusTotal. I just read your answer on the virus issue, and it's dynamic at VirusTotal (the same zip different reports different time), so at least that won't wake me up in the middle of the night.

And finally if example works so, cc.exe can be replaced by that. Am I right? What about c++.exe? Ohhh, I see. Compile option to link it to g++.exe.

So last update. Compiled and replaced cc and c++ and mingw32-make and so far so good. Some Raspberry Pi Pico W project that uses Windows native tools to process output files for microcontroller (could be compiled just once and used later, but now over and over again to test - both Ninja and make - by alias command by cmake.exe --build).

I guess until new release case is closed.

gwald commented 1 year ago

Not using busybox, just a plain winXP cmd, I came across the same issue with cmake not working correctly :/ I changed the install location from C:\w64devkit to C:\mingw32 updated the path environment and it worked fine with: cmake .. -G "MinGW Makefiles"

Strange, but it works :)