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

Cannot compile for Windows - support.cpp - lots of errors #249

Open
SerErris opened this issue Nov 29, 2024 · 7 comments
Open

Cannot compile for Windows - support.cpp - lots of errors #249

SerErris opened this issue Nov 29, 2024 · 7 comments
Assignees
Labels
Milestone

Comments

@SerErris
Copy link

Version Platform Topic
v1.20.3 Windows compilation errors with MinGW-w64 on both Windows and Linux cross compilation

I am trying to compile sjasmplus for windows. For now it is just compiling as it, but I am planning to do some changes for RST mnemonics to embedd correct data word after the RST opcode and parse RST #8, #1234.

However for now I need to be able to compile the original code for Windows. I can compile under Linux (even linux for Windows subsystem) but on both Linux and Windows environements compilation fails on support.cpp.

Certain types are not available (HANDLE, STD_OUTPUT_HANDLE and others, that typically come from windows.h but are not included anywere).

This is the output from trying to compile on Windows with MSYS2/mingw64 environment.

$ make -f Makefile.win
g++.exe -std=c++17 -DNDEBUG -O2 -Wall -static -DUSE_LUA -DMAX_PATH=PATH_MAX -Ilua5.4 -ILuaBridge/Source -Icrc32c -o sjasm/support.o -c sjasm/support.cpp
sjasm/support.cpp:135:8: error: 'HANDLE' does not name a type
  135 | static HANDLE hWinOut;
      |        ^~~~~~
sjasm/support.cpp:136:8: error: 'HANDLE' does not name a type
  136 | static HANDLE hWinIn;
      |        ^~~~~~
sjasm/support.cpp:137:8: error: 'DWORD' does not name a type
  137 | static DWORD dwOriginalOutMode = 0, dwOriginalInMode = 0;
      |        ^~~~~
sjasm/support.cpp: In function 'void restoreOriginalConsoleMode()':
sjasm/support.cpp:141:24: error: 'hWinIn' was not declared in this scope
  141 |         SetConsoleMode(hWinIn, dwOriginalInMode);
      |                        ^~~~~~
sjasm/support.cpp:141:32: error: 'dwOriginalInMode' was not declared in this scope
  141 |         SetConsoleMode(hWinIn, dwOriginalInMode);
      |                                ^~~~~~~~~~~~~~~~
sjasm/support.cpp:141:9: error: 'SetConsoleMode' was not declared in this scope
  141 |         SetConsoleMode(hWinIn, dwOriginalInMode);
      |         ^~~~~~~~~~~~~~
sjasm/support.cpp:142:24: error: 'hWinOut' was not declared in this scope
  142 |         SetConsoleMode(hWinOut, dwOriginalOutMode);
      |                        ^~~~~~~
sjasm/support.cpp:142:33: error: 'dwOriginalOutMode' was not declared in this scope
  142 |         SetConsoleMode(hWinOut, dwOriginalOutMode);
      |                                 ^~~~~~~~~~~~~~~~~
sjasm/support.cpp: In function 'bool autoColorsDetection()':
sjasm/support.cpp:155:9: error: 'hWinOut' was not declared in this scope
  155 |         hWinOut = GetStdHandle(STD_OUTPUT_HANDLE);
      |         ^~~~~~~
sjasm/support.cpp:155:32: error: 'STD_OUTPUT_HANDLE' was not declared in this scope
  155 |         hWinOut = GetStdHandle(STD_OUTPUT_HANDLE);
      |                                ^~~~~~~~~~~~~~~~~
sjasm/support.cpp:155:19: error: 'GetStdHandle' was not declared in this scope
  155 |         hWinOut = GetStdHandle(STD_OUTPUT_HANDLE);
      |                   ^~~~~~~~~~~~
sjasm/support.cpp:156:9: error: 'hWinIn' was not declared in this scope
  156 |         hWinIn = GetStdHandle(STD_INPUT_HANDLE);
      |         ^~~~~~
sjasm/support.cpp:156:31: error: 'STD_INPUT_HANDLE' was not declared in this scope
  156 |         hWinIn = GetStdHandle(STD_INPUT_HANDLE);
      |                               ^~~~~~~~~~~~~~~~
sjasm/support.cpp:157:24: error: 'INVALID_HANDLE_VALUE' was not declared in this scope
  157 |         if (hWinOut != INVALID_HANDLE_VALUE && hWinIn != INVALID_HANDLE_VALUE) {
      |                        ^~~~~~~~~~~~~~~~~~~~
sjasm/support.cpp:158:17: error: 'DWORD' was not declared in this scope
  158 |                 DWORD dwOutMode = 0;
      |                 ^~~~~
sjasm/support.cpp:159:22: error: expected ';' before 'dwInMode'
  159 |                 DWORD dwInMode = 0;
      |                      ^~~~~~~~~
      |                      ;
sjasm/support.cpp:160:46: error: 'dwOutMode' was not declared in this scope
  160 |                 if (GetConsoleMode(hWinOut, &dwOutMode) && GetConsoleMode(hWinIn, &dwInMode)) {
      |                                              ^~~~~~~~~
sjasm/support.cpp:160:21: error: 'GetConsoleMode' was not declared in this scope
  160 |                 if (GetConsoleMode(hWinOut, &dwOutMode) && GetConsoleMode(hWinIn, &dwInMode)) {
      |                     ^~~~~~~~~~~~~~
sjasm/support.cpp:160:84: error: 'dwInMode' was not declared in this scope
  160 |                 if (GetConsoleMode(hWinOut, &dwOutMode) && GetConsoleMode(hWinIn, &dwInMode)) {
      |                                                                                    ^~~~~~~~
sjasm/support.cpp:161:25: error: 'dwOriginalInMode' was not declared in this scope
  161 |                         dwOriginalInMode = dwInMode;
      |                         ^~~~~~~~~~~~~~~~
sjasm/support.cpp:162:25: error: 'dwOriginalOutMode' was not declared in this scope
  162 |                         dwOriginalOutMode = dwOutMode;
      |                         ^~~~~~~~~~~~~~~~~
sjasm/support.cpp:165:38: error: 'ENABLE_VIRTUAL_TERMINAL_PROCESSING' was not declared in this scope
  165 |                         dwOutMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sjasm/support.cpp:166:37: error: 'ENABLE_VIRTUAL_TERMINAL_INPUT' was not declared in this scope
  166 |                         dwInMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sjasm/support.cpp:167:32: error: 'SetConsoleMode' was not declared in this scope
  167 |                         return SetConsoleMode(hWinOut, dwOutMode) && SetConsoleMode(hWinIn, dwInMode);
      |                                ^~~~~~~~~~~~~~
make: *** [Makefile.win:91: sjasm/support.o] Error 1

I tried to include windows.h in here:

#if defined (_WIN32) || defined (__CYGWIN__)
	// cygwin: O_BINARY is in fcntl.h, setmode is in io.h
	// MSVC: _O_BINARY and _setmode
	// #include <windows.h>
	#include <fcntl.h>
	#include <io.h>
	#include <windows.h>
#endif

But then I get other errors, which I even less understand:

$ make -f Makefile.win
g++.exe -std=c++17 -DNDEBUG -O2 -Wall -static -DUSE_LUA -DMAX_PATH=PATH_MAX -Ilua5.4 -ILuaBridge/Source -Icrc32c -o sjasm/support.o -c sjasm/support.cpp
In file included from E:/msys64/mingw64/include/minwindef.h:163,
                 from E:/msys64/mingw64/include/windef.h:9,
                 from E:/msys64/mingw64/include/windows.h:69,
                 from sjasm/support.cpp:121:
E:/msys64/mingw64/include/winnt.h:383:21: error: expected unqualified-id before ',' token
  383 |   typedef char TCHAR, *PTCHAR;
      |                     ^
E:/msys64/mingw64/include/winnt.h:383:11: error: two or more data types in declaration of 'PTCHAR'
  383 |   typedef char TCHAR, *PTCHAR;
      |           ^~~~
In file included from E:/msys64/mingw64/include/winbase.h:36,
                 from E:/msys64/mingw64/include/windows.h:70:
E:/msys64/mingw64/include/sysinfoapi.h:62:27: error: ambiguating new declaration of 'DWORD GetTickCount()'
   62 |   WINBASEAPI DWORD WINAPI GetTickCount (VOID);
      |                           ^~~~~~~~~~~~
sjasm/support.cpp:107:6: note: old declaration 'long int GetTickCount()'
  107 | long GetTickCount() {
      |      ^~~~~~~~~~~~
make: *** [Makefile.win:91: sjasm/support.o] Error 1

So I think something is missing in my compilation environment, but I cannot figure out what it is.

@SerErris SerErris added the bug label Nov 29, 2024
@ped7g
Copy link
Collaborator

ped7g commented Nov 29, 2024

While the windows are currently broken anyway because of my attempt to add new feature with include paths, that shouldn't cause this missing HANDLE.

I have already seen it in the CI, but I can't figure out what changed, I don't remember touching support.cpp or includes in a way to make this happen and doing a quick look through history of commits since last release I haven't found anything suspicious either. It's almost as if something changed in the toolchain, or I'm blind. Or the standard set to c++17 from gnu++14?

If you will be able to hunt this down and find root cause, I'll be very thankful, as I don't have any windows system to test this except the CI servers, which seems to sometimes build it, last commit:

ah.. now I see, the VS build will compile, the mingw fails same way as you describe.

Can you try to enable GNU extensions? (make: CXXFLAGS?=-std=gnu++17 $(CFLAGS), or cmake: set(CMAKE_CXX_EXTENSIONS ON) )

Looking at build logs now, I'm 99% it's this commit:
3729d65

So it's either those GNU extensions being switched off, or move from C++14 to C++17.

If you have windows at hand and time to toy with this, try to find which one it is, thank you.

WRT to the main fail on windows - I'm planning to rewrite all file handling with std::filesystem to make windows build work correctly again, you can try to work on your rst feature branching from here meanwhile:
214e3b7

That one should work on windows... then later we can merge after I finish the std::fs thing, but lately I have difficult time to put any hours into sjasmplus, so be prepared for this to take some undefined time (I hope to release next version this year, but it could fizzle out).

Anyway, you can get more familiar with the project as is right now, keep asking if you have questions (I'm also on Next discord and one of the "ZX Spectrum" discords as "Ped7g" if you want to discuss something online.

Thank you for understanding and patience. :)

@ped7g ped7g self-assigned this Nov 29, 2024
@ped7g ped7g added this to the v1.21.0 milestone Nov 29, 2024
@SerErris
Copy link
Author

SerErris commented Dec 2, 2024

Thanks ped7g, really appreaciate your input. I will have little time until Thrusday to test it, but then will work through your suggestions.

@SerErris
Copy link
Author

SerErris commented Dec 2, 2024

Okay, I took some time today and can confirm that CXXFLAGS=-std=gnu++17 $(CFLAGS) works.

I messed up something else, so deleted everything and downloaded from GIT again and it now works, with the provided Makefile.win, but with the change above.

The total installation is now pretty simple.

Download and install MSYS2 as described in here:
https://www.msys2.org/

Then start MSYS2 and inside download the following three packages:

pacman -S git
pacman -S make
pacman -S mingw-w64-x86_64-gcc

Then start the MSYS2 environment for mingw (there is a start menu entry).

Then download the software:
git clone --recursive -j8 https://github.com/z00m128/sjasmplus.git

And then just edit the Makefile.win file and then compile it:
make -f Makefile.win

It compiles correctly and you have a compiled windows version.

$ ./sjasmplus.exe --help
SjASMPlus Z80 Cross-Assembler v1.20.3 (https://github.com/z00m128/sjasmplus)
Based on code of SjASM by Sjoerd Mastijn (http://www.xl2s.tk)
Copyright 2004-2024 by Aprisobal and all other participants

Usage:
sjasmplus [options] sourcefile(s)

Option flags as follows:
  -h or --help[=warnings]  Help information (you see it)
  --zxnext[=cspect]        Enable ZX Spectrum Next Z80 extensions (Z80N)
  --i8080                  Limit valid instructions to i8080 only (+ no fakes)
  --lr35902                Sharp LR35902 CPU instructions mode (+ no fakes)
  --outprefix=<path>       Prefix for save/output/.. filenames in directives
  -i <path> or -I <path> or --inc= <path> (--inc only to empty the list)
                           Include path (later defined have higher priority)
  --lst[=<filename>]       Save listing to <filename> (<source>.lst is default)
  --lstlab[=sort]          Append [sorted] symbol table to listing
  --sym=<filename>         Save symbol table to <filename>
  --exp=<filename>         Save exports to <filename> (see EXPORT pseudo-op)
  --raw=<filename>         Machine code saved also to <filename> (- is STDOUT)
  --sld[=<filename>]       Save Source Level Debugging data to <filename>
 Note: use OUTPUT, LUA/ENDLUA and other pseudo-ops to control output
 Logging:
  --nologo                 Do not show startup message
  --msg=[all|war|err|none|lst|lstlab]
                           Stderr messages verbosity ("all" is default)
  --fullpath               Show full path to file in errors
  --color=[on|off|auto]    Enable or disable ANSI coloring of warnings/errors
 Other:
  -D<NAME>[=<value>] or --define <NAME>[=<value>]
                           Define <NAME> as <value>
  -                        Reads STDIN as source (even in between regular files)
  --longptr                No device: program counter $ can go beyond 0x10000
  --reversepop             Enable reverse POP order (as in base SjASM version)
  --dirbol                 Enable directives from the beginning of line
  --dos866                 Encode from Windows codepage to DOS 866 (Cyrillic)
  --syntax=<...>           Adjust parsing syntax, check docs for details.

So I can confirm it was just the gnu++17 entry that needs change.

@SerErris
Copy link
Author

SerErris commented Dec 2, 2024

Here is the edited makefile...
Makefile.txt

@ped7g
Copy link
Collaborator

ped7g commented Dec 2, 2024

Thank you for confirming it's the gnu extension which makes it work under mingw.

I expect support.cpp to be cut down a bit after the migration to std::filesystem, so I will revisit this later, in ideal case I would like to stick to c++17 only, but if it's enough to change it only makefile.win, then I really don't care too much, windows details are for me personally out of scope, z00m and others have to deal with that OS.

@z00m128
Copy link
Owner

z00m128 commented Dec 3, 2024

To be honest, Windows is also out of my scope. My last windows notebook died several months ago and I have no intention of getting a new one. What else I'm willing to do is install Windows 10 in a virtual machine, because my current Linux laptop came with an windows OEM license. Then I can still do those Windows 10 builds, but I refuse to mess with binaries for Windows 7 and older.

@z00m128
Copy link
Owner

z00m128 commented Dec 4, 2024

Recommended windows toolchain was updated to something current, and I also temporarily modified Makefile.win according to the proposal (CXXFLAGS=-std=gnu++17 instead of c++17).

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

No branches or pull requests

3 participants