LIJI32 / SameBoy

Game Boy and Game Boy Color emulator written in C
https://sameboy.github.io/
Other
1.69k stars 212 forks source link

Windows compilation fails when displaying stdout (on non-English locale) #164

Closed rzumer closed 5 years ago

rzumer commented 5 years ago

This is a bit of a weird issue. Using the standard MSVC configuration (running in x64_x86 Cross Tools Command Prompt for VS 2017), compilation fails with a simple "error 1" when building the boot ROM. This seems to be due to using a non-English/Western locale (I use Japanese locale). Log below if you would like to pinpoint the cause.

There are two solutions:

Is it possible to call CHCP 65001 when compiling on Windows with MSVC as part of the build process? If it cannot be solved at the source, that would be the best solution in my opinion. It changes the code page to UTF-8.

../Core/gb.c: In function 'GB_is_inited':
../Core/gb.c:529:25: warning: multi-character character constant [-Wmultichar]
     return gb->magic == 'SAME';
                         ^~~~~~
../Core/gb.c: In function 'reset_ram':
../Core/gb.c:569:31: warning: implicit declaration of function 'random'; did you mean 'rand'? [-Wimplicit-function-declaration]
                 gb->ram[i] = (random() & 0xFF);
                               ^~~~~~
                               rand
../Core/gb.c: In function 'GB_reset':
../Core/gb.c:700:28: warning: multi-character character constant [-Wmultichar]
     gb->magic = (uintptr_t)'SAME';
                            ^~~~~~
../Core/sgb.c: In function 'random_double':
../Core/sgb.c:685:14: warning: implicit declaration of function 'random'; did you mean 'rand'? [-Wimplicit-function-declaration]
     return ((random() % 0x10001) - 0x8000) / (double) 0x8000;
              ^~~~~~
              rand
../Core/apu.c: In function 'update_sample':
../Core/apu.c:62:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         if (*(uint32_t *)&(gb->apu_output.current_sample[index]) != *(uint32_t *)&output) {
         ^~
../Core/apu.c:62:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
../Core/apu.c: In function 'render':
../Core/apu.c:72:0: warning: ignoring #pragma unroll  [-Wunknown-pragmas]
     #pragma unroll

../Core/apu.c:129:0: warning: ignoring #pragma unroll  [-Wunknown-pragmas]
             #pragma unroll

../Core/apu.c: In function 'GB_apu_run':
../Core/apu.c:377:0: warning: ignoring #pragma unroll  [-Wunknown-pragmas]
     #pragma unroll

../Core/display.c: In function 'fifo_push_bg_row':
../Core/display.c:30:0: warning: ignoring #pragma unroll  [-Wunknown-pragmas]
         #pragma unroll

../Core/display.c:46:0: warning: ignoring #pragma unroll  [-Wunknown-pragmas]
         #pragma unroll

../Core/display.c: In function 'fifo_overlay_object_row':
../Core/display.c:73:0: warning: ignoring #pragma unroll  [-Wunknown-pragmas]
     #pragma unroll

../Core/display.c: In function 'GB_get_oam_info':
../Core/display.c:1120:0: warning: ignoring #pragma unroll  [-Wunknown-pragmas]
             #pragma unroll

../Core/sm83_cpu.c: In function 'rlc_r':
../Core/sm83_cpu.c:1173:17: warning: '<<' in boolean context, did you mean '<' ? [-Wint-in-bool-context]
     if (!(value << 1)) {
          ~~~~~~~^~~~~
make[2]: write error
make[1]: *** [../build/bin/BootROMs/agb_boot.bin] エラー 1
make[1]: write error
make: *** [libretro] エラー 1
LIJI32 commented 5 years ago

I'm a bit confused, are you building the SDL frontend or the libretro core? If it's the former – I only support clang (On all platforms) and gcc (On platforms other than macOS and Windows). If it's the latter, you should open an issue on libretro's fork of SameBoy, as they're the ones maintaining the build system for the libretro core, and I don't even have a VM where I can even compile SameBoy with MSVC to test if it works. Am I misunderstanding the problem?

rzumer commented 5 years ago

The error is related to the boot ROM. I doubt it has anything to do with libretro. It's building with the default Makefile, so Clang I guess (I mixed it up due to the dependency on VS/MSVC headers).

The last 4 lines in the log are the relevant ones, the rest is just standard build output. エラー means "Error". There is no information besides that so I don't know what is causing it exactly.

LIJI32 commented 5 years ago

Can you confirm running CHCP 65001 before running make fixes this issue? Also, what's the exact make command you're using, and does it include -j? It tends to fail with cryptic errors on Windows sometimes.

rzumer commented 5 years ago

I tested changing the code page at the time of the original report, and it did solve the issue. I followed the instructions in the readme, so it was just make.

By the way, my default code page is 932.

LIJI32 commented 5 years ago

I'm unable to reproduce this on my setup. Is there any chance you're compiling SameBoy from a path that contains non-ASCII characters?

rzumer commented 5 years ago

The root is C:\Users\rzumer\Projects\SameBoy. I just reproduced it again with no target. Sorry, actually that was not the same error. I don't have SDL set up to compile the default target, so I can only test this via libretro (that said, given that the error points to the boot ROM I doubt that it is a libretro error).

Note: to get the proper output with my code page, I need to redirect stderr to a file (e.g. make libretro 2>builderr.log). Otherwise it is still possible to tell that there is an error, but the text is garbled. I also call make clean before testing.

LIJI32 commented 5 years ago

Does adding

ifeq ($(PLATFORM),windows32)
_ := $(shell chcp 65001)
endif

Right before ifeq ($(PLATFORM),Darwin) in the Makefile fixed the problem for you?

rzumer commented 5 years ago

Yes, that works for me.