dave_gnukem icon indicating copy to clipboard operation
dave_gnukem copied to clipboard

emscripten fails to compile

Open enderandrew opened this issue 11 months ago • 2 comments

This may be because the project has moved to SDL2.

If I try to run:

make -f Makefile.em I get:

em++ -Wall -Wno-switch -DDEBUG  -s WASM=1 -s USE_SDL_MIXER=1 --preload-file ./data -s ALLOW_MEMORY_GROWTH=1 --use-preload-plugins -s STB_IMAGE=1 -c src/main.cpp -o src/main.o
em++: warning: linker setting ignored during compilation: 'WASM' [-Wunused-command-line-argument]
em++: warning: linker setting ignored during compilation: 'ALLOW_MEMORY_GROWTH' [-Wunused-command-line-argument]
em++: warning: linker setting ignored during compilation: 'STB_IMAGE' [-Wunused-command-line-argument]
em++: warning: linker flag ignored during compilation: '--preload-file' [-Wunused-command-line-argument]
em++: warning: linker flag ignored during compilation: '--use-preload-plugins' [-Wunused-command-line-argument]
In file included from src/main.cpp:36:
In file included from src/djinput.h:15:
/mnt/d/Development/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl/SDL_events.h:1:2: error: "To use the emscripten port of SDL use -sUSE_SDL or -sUSE_SDL=2"
    1 | #error "To use the emscripten port of SDL use -sUSE_SDL or -sUSE_SDL=2"

If I had the flag of -sUSE_SDL like this:

FLAGS=-s WASM=1 -s USE_SDL=1 -s USE_SDL_MIXER=1 --preload-file ./data -s ALLOW_MEMORY_GROWTH=1 --use-preload-plugins -s STB_IMAGE=1

I now get errors with it somehow pulling in both SDL 1 and 2 headers. Trying to change the flags to USE_SDL=2 and USE_SDL2_MIXER also combines SDL 1 and SDL 2 headers.

In file included from /mnt/d/Development/emsdk/upstream/emscripten/cache/sysroot/include/SDL2/SDL_mixer.h:32: /mnt/d/Development/emsdk/upstream/emscripten/cache/sysroot/include/SDL2/SDL_stdinc.h:182:5: error: redefinition of enumerator 'SDL_FALSE' 182 | SDL_FALSE = 0, | ^ /mnt/d/Development/emsdk/upstream/emscripten/cache/sysroot/include/SDL/SDL_stdinc.h:117:5: note: previous definition is here 117 | SDL_FALSE = 0,

enderandrew avatar Mar 08 '24 02:03 enderandrew

Hi! Thanks for this report .. see comment: https://github.com/davidjoffe/dave_gnukem/issues/160#issuecomment-2063995700

davidjoffe avatar Apr 18 '24 14:04 davidjoffe

Okay, I've managed to fix compiler errors and get game running at ~18 FPS.

Could not get it run at more FPS, because game update logic is tightly linked to FPS right now.

Feel free to pick relevant changes from my fork https://github.com/midzer/dave_gnukem/tree/emscripten

midzer avatar Apr 18 '24 20:04 midzer