Hi, Sorry if this is a noob question and i have simply failed to setup cross compilation correctly, but when i use the command "nim c --cpu:i386 --os:windows --parallelBuild:1 main.nim" to compile to windows I receive the error
"gcc -c -w -I/home/alex/Nim/lib -o /home/alex/Documents/Programing/Nim/NimGame/nimcache/main.o /home/alex/Documents/Programing/Nim/NimGame/nimcache/main.c In file included from /home/alex/Documents/Programing/Nim/NimGame/nimcache/main.c:8:0:
Error: execution of an external program failed"
Again apologies if this is a noob question I am still very new to nim.
Thanks
Jehan, thank you for reply. I re-read these instructions at least 10 times. Here is my story: a friend of mine asked me to make a simple calculation command line program. The issue is that I have Win7-64, while he - WinXP-32. So, I need cross-compilation. Go to the page you referenced (an aside note: it would be really helpful to have there a table of available symbols for cpu and os). Looks easy:
nim c --cpu:i386 --os:windows --parallelBuild:1 hello.nim
... and I am getting the error above. Which means that Nim compiler used wrong size of int to generate main.c. Shall I file a bug? Shall I install 32-bit Nim in addition to 64-bit one? Shall I try editing nim.cfg ?
You could just get the 32bit Nim and build with that and it should work on both of your target platforms.
On Linux with --cpu:i386 I also need to pass -passC:-m32 --passL:-m32 but I don't know if the MinGW on Windows ships with 32bit compatibility.
Whether you are running the 64-bit or 32-bit version of Nim should be irrelevant. The Nim compiler reads Nim source code and spits out C source code and the latter according to the --cpu and --os command line options, and that's not affected by which version of Nim you use. Trying to compile with the normal gcc is pointless, it creates the error message because it tries to compile for the host platform, not the target platform. The error you are getting is just one indication of that.
What you do need is a C cross-compiler that runs on Linux and targets Windows, then configure it per the cross-compiling instructions I linked above. I believe there is a mingw version that runs on Linux and generates code for Windows, but I've never tried myself.
@def, thank you very much. When trying your switches, I realized that I installed Mingw-w64 in SEH exception mode, which is single target. Re-installation in SJLJ exception mode resolved the issue. Happy days!
@Jehan, thank you as well. You are right that this is not Nim but gcc issue.
Just to summarize...
Topic starter, to solve your problem you need: