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

nim v1.2.0 with cygwin gcc: Compiling any code gives error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’? #13874

Closed
zhopan77 opened this issue Apr 4, 2020 · 3 comments

Comments

@zhopan77
Copy link

zhopan77 commented Apr 4, 2020

Versions:
Nim Compiler Version 1.2.0 [Windows: amd64]
Compiled at 2020-04-03
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 7e83adf
active boot switches: -d:release

Windows 10 64-bit.

Any code, even a simple helloworld.nim wouldn't compile, regardless how I installed Nim (either through choosenim or direct download). The message is:

C:\GoogleDrive\Learning\NimLearning>nim c -r "c:\GoogleDrive\Learning\NimLearning\Oct2019\HelloWorld.nim"
Hint: used config file 'C:\nim-1.2.0\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: HelloWorld [Processing]
c:\GoogleDrive\Learning\NimLearning\Oct2019\HelloWorld.nim(19, 6) Hint: 'yes' is declared but not used [XDeclaredButNotUsed]
CC: stdlib_io.nim
C:\Users\zpan\nimcache\HelloWorld_d\stdlib_io.nim.c: In function ‘stdlib_ioInit000’:
C:\Users\zpan\nimcache\HelloWorld_d\stdlib_io.nim.c:509:16: error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’?
  509 |  _setmode(T1_, _O_BINARY);
      |                ^~~~~~~~~
      |                O_BINARY
C:\Users\zpan\nimcache\HelloWorld_d\stdlib_io.nim.c:509:16: note: each undeclared identifier is reported only once for each function it appears in
Error: execution of an external compiler program 'gcc.exe -c  -w -mno-ms-bitfields   -IC:\nim-1.2.0\lib -Ic:\GoogleDrive\Learning\NimLearning\Oct2019 -o C:\Users\zpan\nimcache\HelloWorld_d\stdlib_io.nim.c.o C:\Users\zpan\nimcache\HelloWorld_d\stdlib_io.nim.c' failed with exit code: 1

I'm using gcc 9.3.0 from cygwin:

zpan@WSPWORK C:\Users\zpan
$ where gcc
C:\cygwin64\bin\gcc.exe

zpan@WSPWORK C:\Users\zpan
$ gcc --version
gcc (GCC) 9.3.0
Copyright (C) 2019 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.
@zhopan77
Copy link
Author

zhopan77 commented Apr 4, 2020

OK I tried using scoop to install nim and use the gcc installed by scoop instead. Compiling worked.

zpan@WSPWORK C:\Users\zpan
$ where gcc
c:\Users\zpan\scoop\apps\gcc\8.1.0.0\bin\gcc.exe
C:\Users\zpan\scoop\apps\gcc\current\bin\gcc.exe

zpan@WSPWORK C:\Users\zpan
$ 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.

So I suspect this is due to gcc version. After downgrading to gcc 8.3.0 in cygwin, the compilation still does not work. So it seems cygwin's gcc just wouldn't work.

@zhopan77 zhopan77 changed the title nim v1.2.0: Compiling any code gives error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’? nim v1.2.0 with gcc 9.x: Compiling any code gives error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’? Apr 4, 2020
@zhopan77 zhopan77 changed the title nim v1.2.0 with gcc 9.x: Compiling any code gives error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’? nim v1.2.0 with cygwin gcc: Compiling any code gives error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’? Apr 4, 2020
@alaviss
Copy link
Collaborator

alaviss commented Apr 4, 2020

This is pretty much expected. The code generated by the Nim compiler targets specifically Windows, not Cygwin.

Cygwin is a POSIX-emulated environment to allow POSIX-compatible code to compile and run natively on Windows. Nim doesn't target this environment, it targets win32 directly, which is why you'll need the mingw compiler to compile the code.

@Araq
Copy link
Member

Araq commented Apr 5, 2020

Cygwin is not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants