Error while compiling example_sdl3_opengl3 for Emscripten #6386

Closed
opened 2023-04-30 00:20:51 +00:00 by roma160 · 2 comments
roma160 commented 2023-04-30 00:20:51 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: 1.89.6 WIP
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl3.cpp + imgui_impl_opengl3.cpp
Compiler: Emscripten 3.1.36
Operating System: Windows

My Issue:

The provided example of using SDL3 backend for ImGui could not be compiled without changes to a backend source code. The result of running the build command right away after cloning the master branch:

>>> make -f .\Makefile.emscripten
process_begin: CreateProcess(NULL, uname -s, ...) failed.
.\Makefile.emscripten:25: pipe: No error
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I../.. -I../../backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1  -c -o main.o main.cpp
shared:INFO: old sanity: 3.1.36|C:/PROGRA~1/emsdk/upstream/bin|17.0
shared:INFO: new sanity: 3.1.36|C:/Program Files/emsdk/upstream/bin|17.0
shared:INFO: (Emscripten: config changed, clearing cache)
shared:INFO: (Emscripten: Running sanity checks)
cache:INFO: generating system headers: sysroot_install.stamp... (this will be cached in "C:\Program Files\emsdk\upstream\emscripten\cache\sysroot_install.stamp" for subsequent builds)
cache:INFO:  - ok
ports:INFO: retrieving port: sdl2 from https://github.com/libsdl-org/SDL/archive/release-2.24.2.zip
ports:INFO: unpacking port: sdl2
cache:INFO: generating port: sysroot\lib\wasm32-emscripten\libSDL2.a... (this will be cached in "C:\Program Files\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libSDL2.a" for subsequent builds)
system_libs:INFO: compiled 115 inputs
cache:INFO:  - ok
main.cpp:10:10: fatal error: 'SDL3/SDL.h' file not found
#include <SDL3/SDL.h>
         ^~~~~~~~~~~~
1 error generated.
em++: error: '"C:/Program Files/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:\Program Files\emsdk\upstream\emscripten\cache\sysroot\include\SDL2" "--sysroot=C:\Program Files\emsdk\upstream\emscripten\cache\sysroot" -Xclang -iwithsysroot/include\compat -DIMGUI_DISABLE_FILE_FUNCTIONS -I../.. -I../../backends -Wall -Wformat -Os -c main.cpp -o main.o' failed (returned 1)
make: *** [.\Makefile.emscripten:71: main.o] Error 1

The main thing I don't really understand, is that in the Makefile of the example there is nothing mentioned about SDL (neither linking or include).

At the same time, if the sources of SDL are provided (was using CMake for that), the error would be different:

--  EXTRA CFLAGS:  -Wno-warn-absolute-paths -idirafter "~/project/libs/SDL/src/video/khronos" -Wall -Wundef -fno-strict-aliasing $<$<COMPILE_LANGUAGE:C>:-Wdeclaration-after-statement> -Wdocumentation -Wdocumentation-unknown-command -fcomment-block-commands=threadsafety -Wshadow
--  EXTRA INCDIRS: -I~/project/build/emscripten_sdl3/libs/SDL/include-config-$<LOWER_CASE:$<CONFIG>> -I~/project/build/emscripten_sdl3/libs/SDL/include -I~/project/libs/SDL/include--  EXTRA LDFLAGS: -Wl,--version-script=~/project/libs/SDL/src/dynapi/SDL_dynapi.sym
--  EXTRA LIBS:    m
--
--  Build Shared Library: FALSE
--  Build Static Library: TRUE
--  Build Static Library with Position Independent Code: OFF
--
-- If something was not detected, although the libraries
-- were installed, then make sure you have set the
-- CFLAGS and LDFLAGS environment variables correctly.
--
-- Configuring done
-- Generating done
-- Build files have been written to: ~/project/build/emscripten_sdl3
Consolidate compiler generated dependencies of target SDL3-static
[ 87%] Built target SDL3-static
Consolidate compiler generated dependencies of target main
[ 88%] Building CXX object CMakeFiles/main.dir/libs/imgui/backends/imgui_impl_sdl3.cpp.o
em++: warning: linker setting ignored during compilation: 'WASM' [-Wunused-command-line-argument]
C:\Users\mario\Documents\Documents\University\OOP\LABS\LAB2_semester2\libs\imgui\backends\imgui_impl_sdl3.cpp:459:35: error:
      use of undeclared identifier 'focused_window'
            SDL_GetWindowPosition(focused_window, &window_x, &window_y);
                                  ^
1 error generated.

And, this issue is fixed (just declaring focused_window in the specified above file), everything compiles successfully.

Basically, I don't understand, why the provided example and building steps for it doesn't work and what would be the way to resolve this issue. Maybe the functionality of SDL3 just isn't implemented for Emscripten yet?

**Version/Branch of Dear ImGui:** Version: 1.89.6 WIP Branch: master **Back-end/Renderer/Compiler/OS** Back-ends: imgui_impl_sdl3.cpp + imgui_impl_opengl3.cpp Compiler: Emscripten 3.1.36 Operating System: Windows **My Issue:** The provided [example of using SDL3 backend for ImGui](https://github.com/ocornut/imgui/tree/7c291ba31b3ad0651ad6341bf08d3bb9eeae2453/examples/example_sdl3_opengl3) could not be compiled without changes to a backend source code. The result of running the build command right away after cloning the master branch: ```bash >>> make -f .\Makefile.emscripten process_begin: CreateProcess(NULL, uname -s, ...) failed. .\Makefile.emscripten:25: pipe: No error em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I../.. -I../../backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o main.o main.cpp shared:INFO: old sanity: 3.1.36|C:/PROGRA~1/emsdk/upstream/bin|17.0 shared:INFO: new sanity: 3.1.36|C:/Program Files/emsdk/upstream/bin|17.0 shared:INFO: (Emscripten: config changed, clearing cache) shared:INFO: (Emscripten: Running sanity checks) cache:INFO: generating system headers: sysroot_install.stamp... (this will be cached in "C:\Program Files\emsdk\upstream\emscripten\cache\sysroot_install.stamp" for subsequent builds) cache:INFO: - ok ports:INFO: retrieving port: sdl2 from https://github.com/libsdl-org/SDL/archive/release-2.24.2.zip ports:INFO: unpacking port: sdl2 cache:INFO: generating port: sysroot\lib\wasm32-emscripten\libSDL2.a... (this will be cached in "C:\Program Files\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libSDL2.a" for subsequent builds) system_libs:INFO: compiled 115 inputs cache:INFO: - ok main.cpp:10:10: fatal error: 'SDL3/SDL.h' file not found #include <SDL3/SDL.h> ^~~~~~~~~~~~ 1 error generated. em++: error: '"C:/Program Files/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:\Program Files\emsdk\upstream\emscripten\cache\sysroot\include\SDL2" "--sysroot=C:\Program Files\emsdk\upstream\emscripten\cache\sysroot" -Xclang -iwithsysroot/include\compat -DIMGUI_DISABLE_FILE_FUNCTIONS -I../.. -I../../backends -Wall -Wformat -Os -c main.cpp -o main.o' failed (returned 1) make: *** [.\Makefile.emscripten:71: main.o] Error 1 ``` The main thing I don't really understand, is that in the [Makefile of the example](https://github.com/ocornut/imgui/blob/7c291ba31b3ad0651ad6341bf08d3bb9eeae2453/examples/example_sdl3_opengl3/Makefile.emscripten) there is nothing mentioned about SDL (neither linking or include). At the same time, if the sources of SDL are provided (was using CMake for that), the error would be different: ```bash -- EXTRA CFLAGS: -Wno-warn-absolute-paths -idirafter "~/project/libs/SDL/src/video/khronos" -Wall -Wundef -fno-strict-aliasing $<$<COMPILE_LANGUAGE:C>:-Wdeclaration-after-statement> -Wdocumentation -Wdocumentation-unknown-command -fcomment-block-commands=threadsafety -Wshadow -- EXTRA INCDIRS: -I~/project/build/emscripten_sdl3/libs/SDL/include-config-$<LOWER_CASE:$<CONFIG>> -I~/project/build/emscripten_sdl3/libs/SDL/include -I~/project/libs/SDL/include-- EXTRA LDFLAGS: -Wl,--version-script=~/project/libs/SDL/src/dynapi/SDL_dynapi.sym -- EXTRA LIBS: m -- -- Build Shared Library: FALSE -- Build Static Library: TRUE -- Build Static Library with Position Independent Code: OFF -- -- If something was not detected, although the libraries -- were installed, then make sure you have set the -- CFLAGS and LDFLAGS environment variables correctly. -- -- Configuring done -- Generating done -- Build files have been written to: ~/project/build/emscripten_sdl3 Consolidate compiler generated dependencies of target SDL3-static [ 87%] Built target SDL3-static Consolidate compiler generated dependencies of target main [ 88%] Building CXX object CMakeFiles/main.dir/libs/imgui/backends/imgui_impl_sdl3.cpp.o em++: warning: linker setting ignored during compilation: 'WASM' [-Wunused-command-line-argument] C:\Users\mario\Documents\Documents\University\OOP\LABS\LAB2_semester2\libs\imgui\backends\imgui_impl_sdl3.cpp:459:35: error: use of undeclared identifier 'focused_window' SDL_GetWindowPosition(focused_window, &window_x, &window_y); ^ 1 error generated. ``` And, this issue is fixed (just declaring `focused_window` in the specified above file), everything compiles successfully. Basically, I don't understand, why the provided example and building steps for it doesn't work and what would be the way to resolve this issue. Maybe the functionality of SDL3 just isn't implemented for Emscripten yet?
gvanem commented 2023-05-20 17:55:25 +00:00 (Migrated from github.com)

I get another error on examples\example_sdl3_opengl3\main.cpp. The function SDL_CreateWindow() now takes
6 parameters (not 4 as in the code). Error from clang-cl was:

examples/example_sdl3_opengl3/main.cpp(64,26): error: no matching function for call to 'SDL_CreateWindow'
    SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL3+OpenGL3 example", 1280, 720, window_flags);
                         ^~~~~~~~~~~~~~~~
f:/MinGW32/src/Graphics/SDL/include\SDL3/SDL_video.h(675,37): note: 
candidate function not viable: requires 6 arguments, but 4 were provided

extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags);
                                    ^

Not sure it's related to the above. But I patched like this:

--- a/examples/example_sdl3_opengl3/main.cpp 2023-05-20 18:42:02
+++ b/examples/example_sdl3_opengl3/main.cpp 2023-05-20 19:49:03
@@ -61,7 +61,7 @@
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
     SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
     SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN);
-    SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL3+OpenGL3 example", 1280, 720, window_flags);
+    SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL3+OpenGL3 example", 1280, 720, 1200, 800, window_flags);
     if (window == nullptr)
     {
         printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());

And the program ran just fine.

I get another error on `examples\example_sdl3_opengl3\main.cpp`. The function `SDL_CreateWindow()` now takes 6 parameters (not 4 as in the code). Error from `clang-cl` was: ```c examples/example_sdl3_opengl3/main.cpp(64,26): error: no matching function for call to 'SDL_CreateWindow' SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL3+OpenGL3 example", 1280, 720, window_flags); ^~~~~~~~~~~~~~~~ f:/MinGW32/src/Graphics/SDL/include\SDL3/SDL_video.h(675,37): note: candidate function not viable: requires 6 arguments, but 4 were provided extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags); ^ ``` Not sure it's related to the above. But I patched like this: ```diff --- a/examples/example_sdl3_opengl3/main.cpp 2023-05-20 18:42:02 +++ b/examples/example_sdl3_opengl3/main.cpp 2023-05-20 19:49:03 @@ -61,7 +61,7 @@ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN); - SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL3+OpenGL3 example", 1280, 720, window_flags); + SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL3+OpenGL3 example", 1280, 720, 1200, 800, window_flags); if (window == nullptr) { printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError()); ``` And the program ran just fine.
ocornut commented 2023-05-30 17:54:18 +00:00 (Migrated from github.com)

On Emscripten support:
I don't believe Emscripten supports SDL3 yet.
I left the Makefile around as I am expecting it to happen as soon as SDL3 stabilize.
I have now pushed 216ae7d to make this clearer.

On the focused window problem, this was fixed on May 4 with 5dc6013713

On your SDL_CreateWindow() problem: You seem to be using an older version of SDL3.
SDL3 is currently in dev and is a fast moving target. In latest work branch that function has 4 parameters.

On Emscripten support: I don't believe Emscripten supports SDL3 yet. I left the Makefile around as I am expecting it to happen as soon as SDL3 stabilize. I have now pushed 216ae7d to make this clearer. On the `focused window` problem, this was fixed on May 4 with 5dc60137139cb9a8b70adc192fcc3549874dc17b On your `SDL_CreateWindow()` problem: You seem to be using an older version of SDL3. SDL3 is currently in dev and is a fast moving target. In latest work branch that function has 4 parameters.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#6386
No description provided.