Issues using SDL2 with Emscripten

Hello there

I am currently trying to port a C++ SDL project to web format using emscripten and clang. There are multiple source files int the project so I have attempted to create a makefile for the project. This is what I have in it.

debug:
emcc $(wildcard src/*.cpp)
-sUSE_SDL=2
-o ./out/build/x64-debug \
-lSDL2
-lSDL2_image
-lSDL2_ttf
-lSDL2_mixer

emcc =02 *.o -o paultris.js ./out/build/x64-debug

When I run make I get the following output.

> emcc src/GameScreen.cpp src/Tetris.cpp src/SDLApp.cpp src/MainMenu.cpp src/Main.cpp src/Sound.cpp \
> -sUSE_SDL=2
> In file included from src/GameScreen.cpp:1:
> In file included from src/GameScreen.h:7:
> src/Text.h:2:10: fatal error: 'SDL_ttf.h' file not found
> #include <SDL_ttf.h>
>          ^~~~~~~~~~~
> 1 error generated.
> emcc: error: 'C:/sdks/emsdk/upstream/bin\clang++.exe -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -IC:\sdks\emsdk\upstream\emscripten\cache\sysroot\include\SDL2 --sysroot=C:\sdks\emsdk\upstream\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat src/GameScreen.cpp -c -o C:\Users\paulk\AppData\Local\Temp\emscripten_temp_y04p4vbz\GameScreen_0.o' failed (returned 1)
> make: *** [makefile:11: debug] Error 1

![image|690x165](upload://vDmLiHufOgZfOk5y9LiNhWSah4R.png)

I don't know why it cannot open SDL_ttf.h as I have added the flag for it in the makefile. Is there something else that I need to type?

Regards,
OzzieKing

My makefile still has -s USE_SDL_TTF=2. I’m not sure whether it is strictly necessary any more, but it can’t do any harm to include it.

Hi. That seems to have fixed that part of the problem. It downloaded and installed a new port the next time I ran the makefile.

Ok I have fixed all of that but I am now getting this error:

emcc src/GameScreen.cpp src/Tetris.cpp src/SDLApp.cpp src/MainMenu.cpp src/Text.cpp src/Main.cpp src/Sound.cpp \

In file included from src/GameScreen.cpp:1:
In file included from src/GameScreen.h:2:
C:\sdks\emsdk\upstream\emscripten\cache\sysroot/include\fakesdl\SDL.h:1:2: error: “To use the emscripten port of SDL use
-sUSE_SDL or -sUSE_SDL=2”
#error “To use the emscripten port of SDL use -sUSE_SDL or -sUSE_SDL=2”
^
In file included from src/GameScreen.cpp:1:
In file included from src/GameScreen.h:7:
In file included from src/Text.h:3:
C:\sdks\emsdk\upstream\emscripten\cache\sysroot/include\fakesdl\SDL.h:1:2: error: “To use the emscripten port of SDL use
-sUSE_SDL or -sUSE_SDL=2”
#error “To use the emscripten port of SDL use -sUSE_SDL or -sUSE_SDL=2”

for some reason including the SDL headers from within my header files do not work. But including them in the cpp files seems to be fine.