Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile/link broken for nim (64-bit only) on Windows #12536

Closed
rivy opened this issue Oct 27, 2019 · 6 comments
Closed

Compile/link broken for nim (64-bit only) on Windows #12536

rivy opened this issue Oct 27, 2019 · 6 comments

Comments

@rivy
Copy link

rivy commented Oct 27, 2019

nim (64-bit version) compiles fail when using gcc (64-bit version), disagreeing on target architecture. Failures occur even when specifying cpu. The included default nim configuration is used.

gcc otherwise works fully/correctly on the same machine.

Notably, using nim (32-bit) with gcc (32-bit) works just fine (although obviously unable to compile to a 64-bit target).

64-bit output

C:\Users\Roy\nim\hello-world>type hello.nim
# This is a comment
echo "Hello, ", "world!"

C:\Users\Roy\nim\hello-world>gcc --version
gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 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.

C:\Users\Roy\nim\hello-world>nim --version
Nim Compiler Version 1.0.2 [Windows: amd64]
Compiled at 2019-10-22
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 193b3c66bbeffafaebff166d24b9866f1eaaac0e
active boot switches: -d:release

C:\Users\Roy\nim\hello-world>nim c hello.nim
Hint: used config file 'C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\Roy\AppData\Roaming\nim\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: hello [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: hello.nim
Error: execution of an external compiler program 'gcc.exe -c  -w -mno-ms-bitfields  -IC:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\lib -IC:\Users\Roy\nim\hello-world -o C:\Users\Roy\nimcache\hello_d\@mhello.nim.c.o C:\Users\Roy\nimcache\hello_d\@mhello.nim.c' failed with exit code: 1

In file included from C:\Users\Roy\nimcache\hello_d\@mhello.nim.c:9:
C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\lib/nimbase.h:457:13: error: size of array 'Nim_and_C_compiler_disagree_on_target_architecture' is negative
 typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

C:\Users\Roy\nim\hello-world>nim --cc:gcc --cpu:amd64 c hello.nim
Hint: used config file 'C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\Roy\AppData\Roaming\nim\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: hello [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: hello.nim
Error: execution of an external compiler program 'gcc.exe -c -w -mno-ms-bitfields  -IC:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\lib -IC:\Users\Roy\nim\hello-world -o C:\Users\Roy\nimcache\hello_d\@mhello.nim.c.o C:\Users\Roy\nimcache\hello_d\@mhello.nim.c' failed with exit code: 1

In file included from C:\Users\Roy\nimcache\hello_d\@mhello.nim.c:9:
C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\lib/nimbase.h:457:13: error: size of array 'Nim_and_C_compiler_disagree_on_target_architecture' is negative
 typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

C:\Users\Roy\nim\hello-world>nim --cc:gcc --cpu:i386 c hello.nim
Hint: used config file 'C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\Roy\AppData\Roaming\nim\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: hello [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: hello.nim
Error: execution of an external compiler program 'gcc.exe -c -w -mno-ms-bitfields  -IC:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\lib -IC:\Users\Roy\nim\hello-world -o C:\Users\Roy\nimcache\hello_d\@mhello.nim.c.o C:\Users\Roy\nimcache\hello_d\@mhello.nim.c' failed with exit code: 1

In file included from C:\Users\Roy\nimcache\hello_d\@mhello.nim.c:9:
C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x64\lib/nimbase.h:457:13: error: size of array 'Nim_and_C_compiler_disagree_on_target_architecture' is negative
 typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

32-bit output

C:\Users\Roy\nim\hello-world>type hello.nim
# This is a comment
echo "Hello, ", "world!"

C:\Users\Roy\nim\hello-world>gcc --version
gcc (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 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.

C:\Users\Roy\nim\hello-world>nim --version
Nim Compiler Version 1.0.2 [Windows: i386]
Compiled at 2019-10-22
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 193b3c66bbeffafaebff166d24b9866f1eaaac0e
active boot switches: -d:release

C:\Users\Roy\nim\hello-world>nim c hello.nim
Hint: used config file 'C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x32\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\Roy\AppData\Roaming\nim\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: hello [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: hello.nim
Hint:  [Link]
Hint: operation successful (14407 lines compiled; 1.596 sec total; 10.633MiB peakmem; Debug Build) [SuccessX]

C:\Users\Roy\nim\hello-world>nim --cc:gcc --cpu:i386 c hello.nim
Hint: used config file 'C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x32\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\Roy\AppData\Roaming\nim\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: hello [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: hello.nim
Hint:  [Link]
Hint: operation successful (14407 lines compiled; 1.295 sec total; 10.633MiB peakmem; Debug Build) [SuccessX]

C:\Users\Roy\nim\hello-world>nim --cc:gcc --cpu:amd64 c hello.nim
Hint: used config file 'C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x32\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\Roy\AppData\Roaming\nim\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: hello [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: hello.nim
Error: execution of an external compiler program 'gcc.exe -c -w -mno-ms-bitfields  -IC:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x32\lib -IC:\Users\Roy\nim\hello-world -o C:\Users\Roy\nimcache\hello_d\@mhello.nim.c.o C:\Users\Roy\nimcache\hello_d\@mhello.nim.c' failed with exit code: 1

In file included from C:\Users\Roy\nimcache\hello_d\@mhello.nim.c:9:
C:\Users\Roy\AppData\Local\scoop\apps\nim\1.0.2-x32\lib/nimbase.h:457:13: error: size of array 'Nim_and_C_compiler_disagree_on_target_architecture' is negative
 typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@rivy
Copy link
Author

rivy commented Oct 27, 2019

I'm happy to troubleshoot further if needed and directed.

Thanks for the attention.

@genotrance
Copy link
Contributor

Please retry with -f or delete C:\Users\Roy\nimcache\hello_d.

@rivy
Copy link
Author

rivy commented Oct 27, 2019

Thanks for the quick response.

I had previously seen the cache directory and tried removing both the hello_d and the entire directory without success.

I just tried using the -f option. Unfortunately, no success with that either.

@rivy
Copy link
Author

rivy commented Oct 27, 2019

Hmm... I looked back through the compile and looked again at the local configuration file.

It had a cpu = i386 line in it. Disabling that line corrects the problem.

But, I would have thought nim --cpu:amd64 c hello.nim would have overridden the configuration option and allowed a successful compilation.

@demotomohiro
Copy link
Contributor

demotomohiro commented Oct 29, 2019

You get such error when Nim compiler trying to build a executable file for 32bit CPU with backend C compiler for 64bit CPU.
In your case, it seems cpu=i386 is set but Nim calls gcc for amd64 CPU.

Nim Compiler User Guide says:

Command line settings have priority over configuration file settings.

But when I set cpu=i386 in nim.cfg and run nim with --cpu:amd64, I got Nim_and_C_compiler_disagree_on_target_architecture error.
It looks like --cpu:amd64 option in a command line doesn't override cpu=i386 option in a configuration file.

I tested following code on 64bit Linux without gcc for i386 CPU.

nim.cfg:

cpu=i386

test.nim:

echo"test"

Output:

user@linux /tmp/tmp $ nim c --cpu:amd64 test.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: used config file '/home/user/.config/nim/nim.cfg' [Conf]
Hint: used config file '/tmp/tmp/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: test [Processing]
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: test.nim
Error: execution of an external compiler program 'gcc -c  -w  -I/usr/lib/nim -I/tmp/tmp -o /tmp/nimcache/d/test/@mtest.nim.c.o
 /tmp/nimcache/d/test/@mtest.nim.c' failed with exit code: 1

In file included from /tmp/nimcache/d/test/@mtest.nim.c:9:
/usr/lib/nim/nimbase.h:457:13: error: size of array ‘Nim_and_C_compiler_disagree_on_target_architecture’ is negative
 typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1
 : -1];
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
user@linux /tmp/tmp $ nim -v
Nim Compiler Version 1.0.2 [Linux: amd64]
Compiled at 2019-10-28
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release

When I set cpu=amd64 in nim.cfg and --cpu:i386 on command line, I got same error.
I also tested same code with same cfg file and same command, I got same error on Windows 8.1.

demotomohiro added a commit to demotomohiro/Nim that referenced this issue Oct 31, 2019
@Araq Araq closed this as completed in 4e0f120 Nov 2, 2019
@rivy
Copy link
Author

rivy commented Nov 3, 2019

Thanks for the fix.
I haven't been able to test it for my setup because the related nightly release doesn't include the windows builds in the assets.

narimiran pushed a commit to narimiran/Nim that referenced this issue Nov 5, 2019
kiyolee pushed a commit to kiyolee/nim that referenced this issue Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants