Cross compiling Nimes to C

I wrote a Nim program,

echo("Hello.") 

And then I tried to compile the compilation for a Linux machine,

 nim c --cpu:i386 --os:linux -c hello.nim 

This produced the following conclusion:

 config/nim.cfg(45, 2) Hint: added path: '/Users/connor/.babel/pkgs/' [Path] config/nim.cfg(46, 2) Hint: added path: '/Users/connor/.nimble/pkgs/' [Path] Hint: used config file '/usr/local/lib/nim-0.10.2/config/nim.cfg' [Conf] Hint: system [Processing] Hint: hello [Processing] Hint: operation successful (8753 lines compiled; 0.140 sec total; 14.148MB)[SuccessX] 

At this point, I went to the nimcache/ directory and tried to execute:

 gcc hello.c -o hello.o 

But this gave me an error:

 hello.c:5:10: fatal error: 'nimbase.h' file not found #include "nimbase.h" ^ 1 error generated. 

I thought, β€œNot a biggie, I just find nimbase.h and put it in the nimcache directory there,” but after that I got a new error,

 In file included from hello.c:5: ./nimbase.h:385:28: error: 'assert_numbits' declared as an array with a negative size ...sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1]; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. 

I'm not sure what I should do with this. I tried using the --genScript , but this led to similar errors. I am running OS X Yosemite.

Thanks!

Update:

I was not sure how many architectures were supported for the --cpu: option, but I found a (incomplete?) List on What makes it practical on a blog. I ended up calling

 nim c --cpu:amd64 --os:linux -c hello.nim 

This prevented the error that I saw when compiling in my Linux box. If you use Linux or OS X, you don’t know what architecture you can name,

 less /proc/cpuinfo 
+5
source share
2 answers

The final problem is that you are using gcc for x86_64 arch, while the sources were generated for the i386 arch.

+5
source

I had the same problem when I was getting nim to compile Windows executables from a GNU / Linux machine, so I made a bash script. It takes the path to the directory containing the *.nim source files and the name of the executable file for output.

I am sure you could exchange the GCC compiler (MinGW in this case) and change the --os: switch if necessary:

 #!/usr/bin/env bash # Nim must generate C sources only, to be fed to MingW nim c --cpu:amd64 --os:windows --opt:speed --embedsrc --threads:on --checks:on -c -d:release $1/*.nim # Copy nimbase.h so MingW32 can find it during compilation and linking cp /opt/Nim/lib/nimbase.h $1/nimcache/nimbase.h mkdir -p $1/bin cd $1/nimcache && x86_64-w64-mingw32-gcc -save-temps $1/nimcache/*.c -o $1/bin/$2.exe rm $1/nimcache/*.{i,s} # only care about *.o objects ls -lAhF $1/nimcache ls -lAhF $1/bin 
+2
source

All Articles