I have a project that builds a very simple program via cross-compiling using the arm-none-eabi-gcc toolchain. Most cross-compile options given to nim are in the project's nim.cfg only the gcc binary is given on the command line. On a MacOS host, nim finds the cross-compiler arm-none-eabi-gcc in the PATH. On a Win10 host, nim does NOT find the cross-compiler arm-none-eabi-gcc.exe despite it being in PATH. Any ideas why not?
PS D:\code\nim\arm_sandbox> nim c --arm.standalone.gcc.exe=arm-none-eabi-gcc.exe .\src\before.nim
Hint: used config file 'D:\nim-1.6.10\config\nim.cfg' [Conf]
Hint: used config file 'D:\nim-1.6.10\config\config.nims' [Conf]
Hint: used config file 'D:\code\nim\arm_sandbox\nim.cfg' [Conf]
.........................................................
CC: ../../../nim-1.6.10/lib/system.nim
Error: invocation of external compiler program failed. The system cannot find the file specified.
Additional info: Requested command not found: 'D:\nim-1.6.10\dist\mingw64\bin\arm-none-eabi-gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -w -fmax-errors=4 -mthumb -ID:\nim-1.6.10\lib -ID:\code\nim\arm_sandbox\src -o D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected] D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected]'. OS error: 2
PS D:\code\nim\arm_sandbox> which arm-none-eabi-gcc.exe
/c/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/13.2 Rel1/bin/arm-none-eabi-gcc.exe
A solid guess, but that doesn't seem to be it. After copying the toolchain to a path without spaces and adding that to PATH:
D:\code\nim\arm_sandbox> nim c --arm.standalone.gcc.exe=arm-none-eabi-gcc.exe .\src\before.nim
Hint: used config file 'D:\code\nim-1.6.10\config\nim.cfg' [Conf]
Hint: used config file 'D:\code\nim-1.6.10\config\config.nims' [Conf]
Hint: used config file 'D:\code\nim\arm_sandbox\nim.cfg' [Conf]
.........................................................
CC: ../../../nim-1.6.10/lib/system.nim
Error: invocation of external compiler program failed. The system cannot find the file specified.
Additional info: Requested command not found: 'D:\code\nim-1.6.10\dist\mingw64\bin\arm-none-eabi-gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -w -fmax-errors=4 -mthumb -ID:\code\nim-1.6.10\lib -ID:\code\nim\arm_sandbox\src -o D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected] D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected]'. OS error: 2
D:\code\nim\arm_sandbox> where arm-none-eabi-gcc.exe
D:\dwh\bin\arm-none-eabi\arm-none-eabi-gcc.exe
I've found a clue to this puzzle, but still can't find a solution. When I compile with my cross-compile arguments on the command line, I get a different result than if I compile with the cross-compiler .exe as the only command line argument and the remaining cross-compile args in the nim.cfg.
With cross-compile args on the command line, the cross-compiler is called properly on system.nim, but things go haywire on the second call to the cross-compiler:
D:\code\nim\arm_sandbox> nim c --cpu:arm --os:any --cc:gcc --arm.any.gcc.exe=arm-none-eabi-gcc .\src\main_4.nim
Hint: used config file 'D:\code\nim-1.6.10\config\nim.cfg' [Conf]
Hint: used config file 'D:\code\nim-1.6.10\config\config.nims' [Conf]
Hint: used config file 'D:\code\nim\arm_sandbox\nim.cfg' [Conf]
........................................................
CC: ../../../nim-1.6.10/lib/system.nim
arm-none-eabi-gcc.exe -c -w -fmax-errors=4 -mthumb -ID:\code\nim-1.6.10\lib -ID:\code\nim\arm_sandbox\src -o D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected] D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected]
CC: main_4.nim
arm-none-eabi-gcc.exe -c -w -fmax-errors=4 -mthumb -ID:\code\nim-1.6.10\lib -ID:\code\nim\arm_sandbox\src -o D:\code\nim\arm_sandbox\build\nimcache\@mmain_4.nim.c.o D:\code\nim\arm_sandbox\build\nimcache\@mmain_4.nim.c
arm-none-eabi-gcc.exe: fatal error: cannot execute 'cc1': CreateProcess: No such file or directory
compilation terminated.
Error: execution of an external compiler program 'arm-none-eabi-gcc.exe -c -w -fmax-errors=4 -mthumb -ID:\code\nim-1.6.1 lib -IDarm-none-eabi-gcc.exe::
mnr\ pj avfatal error: tn nicannot execute 'm\a m_cc1sa db': CreateProcess: No such file or directory
coompxil\astrci -oo nD: \gtrmen\rprmj\iavntna\ntime\adrm._s
andbox\build\nimcache\@m..@s..@[email protected]@[email protected] D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected]' failed with exit code: 1
Whereas with the cross-compile args in nim.cfg, the cross-compiler is mistakenly called with the path to the desktop gcc prefixed to the given cross-compiler .exe:
D:\code\nim\arm_sandbox> nim c --arm.any.gcc.exe=arm-none-eabi-gcc .\src\main_4.nim
Hint: used config file 'D:\code\nim-1.6.10\config\nim.cfg' [Conf]
Hint: used config file 'D:\code\nim-1.6.10\config\config.nims' [Conf]
Hint: used config file 'D:\code\nim\arm_sandbox\nim.cfg' [Conf]
........................................................
CC: ../../../nim-1.6.10/lib/system.nim
D:\code\nim-1.6.10\dist\mingw64\bin\arm-none-eabi-gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -w -fmax-errors=4 -mthumb -ID:\code\nim-1.6.10\lib -ID:\code\nim\arm_sandbox\src -o D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected] D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected]
Error: invocation of external compiler program failed. The system cannot find the file specified.
Additional info: Requested command not found: 'D:\code\nim-1.6.10\dist\mingw64\bin\arm-none-eabi-gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -w -fmax-errors=4 -mthumb -ID:\code\nim-1.6.10\lib -ID:\code\nim\arm_sandbox\src -o D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected] D:\code\nim\arm_sandbox\build\nimcache\@m..@s..@[email protected]@[email protected]'. OS error: 2
Solved!
In the previous step, I learned that the cross-compile arguments MUST be on the command line, they cannot be in nim.cfg. Combine this with the following.
The next clue in this puzzle was to try the arm_sandbox project on another Windows10 machine . . . and it worked. I narrowed the problem to the version of the arm-none-eabi-gcc toolchain I used to cross-compile.
A version of arm-none-eabi-gcc circa 2016 is what works, while a recent release circa 2023 is what fails.
Works:
arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160609 (release) [ARM/embedded-5-branch revision 237715]
Copyright (C) 2015 Free Software Foundation, Inc.
Fails:
arm-none-eabi-gcc.exe (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7)) 13.2.1 20231009
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bisecting the versions of toolchains to find where the incompatibility was introduced is an exercise for the reader.