libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.55k stars 1.77k forks source link

SDL_QueueAudio is undeclared when compiling with emscripten #7757

Closed sere3925sere closed 1 year ago

sere3925sere commented 1 year ago

Test program, testsdl.c:

#include <SDL/SDL.h>

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

int main(int argc, char** argv) {
    if (0) {
        SDL_AudioDeviceID audio_device;
        SDL_QueueAudio(audio_device, NULL, 80);
    }
    return 0;
}

Version of emscripten/emsdk:

emcc -v

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.39 (36f871819b566281d160470a1ec4515f379e9f77)
clang version 17.0.0 (https://github.com/llvm/llvm-project c672c3fe05adbb590abc99da39143b55ad510538)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\shared\emsdk\upstream\bin

Failing command line in full:

emcc testsdl.c -sUSE_SDL=2

testsdl.c:10:3: error: call to undeclared function 'SDL_QueueAudio'; ISO C99 and later do not support implicit function
declarations [-Wimplicit-function-declaration]
SDL_QueueAudio(audio_device, NULL, 80);
^
1 error generated.
emcc: error: 'C:/shared/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 -Werror=implicit-function-declaration -IC:\shared\emsdk\upstream\emscripten\cache\sysroot\include\SDL2 --sysroot=C:\shared\emsdk\upstream\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat testsdl.c -c -o C:\Users\username\AppData\Local\Temp\emscripten_temp_x1vr0j5w\testsdl_0.o' failed (returned 1)

Full link command and output with -v appended:

emcc testsdl.c -sUSE_SDL=2 -v

"C:/shared/emsdk/upstream/bin\clang.exe" --version
"C:/shared/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 -Werror=implicit-function-declaration -IC:\shared\emsdk\upstream\emscripten\cache\sysroot\include\SDL2 --sysroot=C:\shared\emsdk\upstream\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat -v testsdl.c -c -o C:\Users\username\AppData\Local\Temp\emscripten_temp_n4co6fn5\testsdl_0.o
clang version 17.0.0 (https://github.com/llvm/llvm-project c672c3fe05adbb590abc99da39143b55ad510538)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\shared\emsdk\upstream\bin
(in-process)
"C:\\shared\\emsdk\\upstream\\bin\\clang.exe" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name testsdl.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -debugger-tuning=gdb -v "-fcoverage-compilation-dir=C:\\Users\\username\\Desktop\\chiptune\\_c_example" -resource-dir "C:\\shared\\emsdk\\upstream\\lib\\clang\\17" -D EMSCRIPTEN -I "C:\\shared\\emsdk\\upstream\\emscripten\\cache\\sysroot\\include\\SDL2" -isysroot "C:\\shared\\emsdk\\upstream\\emscripten\\cache\\sysroot" -internal-isystem "C:\\shared\\emsdk\\upstream\\lib\\clang\\17\\include" -internal-isystem "C:\\shared\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/wasm32-emscripten" -internal-isystem "C:\\shared\\emsdk\\upstream\\emscripten\\cache\\sysroot/include" -Werror=implicit-function-declaration "-fdebug-compilation-dir=C:\\Users\\username\\Desktop\\chiptune\\_c_example" -ferror-limit 19 -fmessage-length=120 -fvisibility=default -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics "-iwithsysroot/include\\compat" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o "C:\\Users\\username\\AppData\\Local\\Temp\\emscripten_temp_n4co6fn5\\testsdl_0.o" -x c testsdl.c
clang -cc1 version 17.0.0 based upon LLVM 17.0.0git default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\shared\emsdk\upstream\emscripten\cache\sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
C:\shared\emsdk\upstream\emscripten\cache\sysroot\include\SDL2
C:\shared\emsdk\upstream\emscripten\cache\sysroot/include\compat
C:\shared\emsdk\upstream\lib\clang\17\include
C:\shared\emsdk\upstream\emscripten\cache\sysroot/include
End of search list.
testsdl.c:10:3: error: call to undeclared function 'SDL_QueueAudio'; ISO C99 and later do not support implicit function
declarations [-Wimplicit-function-declaration]
SDL_QueueAudio(audio_device, NULL, 80);
^
1 error generated.
emcc: error: 'C:/shared/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 -Werror=implicit-function-declaration -IC:\shared\emsdk\upstream\emscripten\cache\sysroot\include\SDL2 --sysroot=C:\shared\emsdk\upstream\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat -v testsdl.c -c -o C:\Users\username\AppData\Local\Temp\emscripten_temp_n4co6fn5\testsdl_0.o' failed (returned 1)

SDL version:

we are linking against SDL version 2.24.2.

Code for getting SDL version:

SDL_version linked;
SDL_GetVersion(&linked);
printf("we are linking against SDL version %d.%d.%d.\n", linked.major, linked.minor, linked.patch);
sere3925sere commented 1 year ago

I replaced #include <SDL/SDL.h> with #include , and it now compiles.

madebr commented 1 year ago

Strange. The include search dirs look okay'ish. I'm wondering what SDL_audio.h is included by SDL.h.

Can you "break" your source again and compile with -E? This will only preprocess your source. The output should contain #line directives that show the full path of included files.

sere3925sere commented 1 year ago

Allright, here is output. output.zip

Also I added this line extern DECLSPEC int SDLCALL SDL_QueueAudio(SDL_AudioDeviceID dev, const void *data, Uint32 len); in emsdk\upstream\emscripten\cache\sysroot\include\SDL2\SDL_audio.h and in emsdk\upstream\emscripten\system\include\SDL\SDL_audio.h Not sure if that made any difference. It still was broken until I changed #include to

madebr commented 1 year ago

You are including SDL/SDL.h. That is the header of SDL 1.2, which is incompatible with SDL2. (SDL3 is also incompatible with both of them)

You need to do #include <SDL2/SDL.h> instead, or #include "SDL.h" as you already did.

For safety, undo your changes to the SDL_audio.h files. The default SDL2 headers declare everything you need.