Skip to content

libsdl.js and self-compiled SDL2 confusion #26271

Open

Description

@magist3r

Emscripten v. 3.1.46, but also present in main.

It's more like a question then a bugreport, but please help me understand this.
If I build my own SDL2 library for Emscripten and provide -sUSE_SDL=0 (which is the default anyway), why old SDL1 libsdl.js is pulled by default?

emscripten/src/modules.mjs

Lines 146 to 148 in efa2897

if (USE_SDL != 2) {
libraries.push('libsdl.js');
}

It is not needed for -sUSE_SDL2 based on this line

emscripten/src/modules.mjs

Lines 156 to 158 in efa2897

if (USE_SDL == 2) {
libraries.push('libegl.js', 'libwebgl.js', 'libhtml5_webgl.js');
}

Is it a bug or is it intentional?

Thanks.

Activity

  1. sbc100 commented on Feb 16, 2026

    @sbc100
    Collaborator

    Yes line 146 should probably be if (USE_SDL == 1) {. In practice is probably doesn't matter since your SDL2 library will take precedence of the JS one.

    I will update line 146 now..

  2. added a commit that references this issue on Feb 16, 2026
    9f08be7
  3. sbc100 commented on Feb 16, 2026

    @sbc100
    Collaborator

    Fix is in #26275

  4. added a commit that references this issue on Feb 16, 2026
    0150668
  5. magist3r commented on Feb 16, 2026

    @magist3r
    Author

    I guess that also could be a problem with SDL2_image and SDL2_ttf as they are also implemented by libsdl.js.

    My original issue was with SDL2_image implicitly included and hid undefined symbols, even though I provided -sUSE_SDL=0 and -sUSE_SDL_IMAGE=0.

  6. sbc100 commented on Feb 16, 2026

    @sbc100
    Collaborator

    I guess that also could be a problem with SDL2_image and SDL2_ttf as they are also implemented by libsdl.js.

    My original issue was with SDL2_image implicitly included and hid undefined symbols, even though I provided -sUSE_SDL=0 and -sUSE_SDL_IMAGE=0.

    Technically it would be SDL_image and SDL_ttf if we are talking about libsdl.js since it only implement SDL 1.2 APIs. But yes when the symbols overlap that could be an issue.

    #26275 should still fix though.

  7. added 3 commits that reference this issue on Feb 16, 2026
    c63cad7
    997a1e0
    ff07e44
  8. magist3r commented on Feb 16, 2026

    @magist3r
    Author

    Technically it would be SDL_image and SDL_ttf if we are talking about libsdl.js since it only implement SDL 1.2 APIs. But yes when the symbols overlap that could be an issue.

    I meant that both USE_SDL_IMAGE and USE_SDL_TTF are still =1 by default https://github.com/emscripten-core/emscripten/blob/main/src/settings.js#L1514, so without libsdl.js it won't work as expected, right?

  9. sbc100 commented on Feb 16, 2026

    @sbc100
    Collaborator

    Ah I see. We should set those to zero too by default.

    However any user of SDL_image.h should be setting setting -sUSE_SDL too. Trying to include SDL_image.h without -sUSE_SDL should result in build error: https://github.com/emscripten-core/emscripten/blob/main/system/include/fakesdl/SDL_image.h

  10. added 3 commits that reference this issue on Feb 16, 2026
    b016b70
    532f8ba
    8c25c74
  11. magist3r commented on Feb 16, 2026

    @magist3r
    Author

    Okay, I see. So everything should be covered then, thanks for clarifications and fixes :)

  12. added a commit that references this issue on Aug 10, 2026
    79d2f0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions