Skip to content

Cannot build SDL images + png/jpg with pthreadsΒ #19410

@GrigoryGraborenko

Description

@GrigoryGraborenko

Hi! Tried both emscripten 3.1.25 and 3.1.38 - currently trying to use SDL image formats like png with a multithreaded emscripten build.

Here are the critical lines from my cmake:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS=png -pthread -s USE_PTHREADS -s SHARED_MEMORY=0")
set(CMAKE_EXE_LINKER_FLAGS "-s ASSERTIONS=0 -s WASM=1 -s USE_WEBGPU=1 -s NO_EXIT_RUNTIME=1 -s STRICT=0 -pthread -s USE_PTHREADS -s SHARED_MEMORY=0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ENVIRONMENT=web,worker -s TEXTDECODER=2 -s ABORTING_MALLOC=0 -s ALLOW_MEMORY_GROWTH=0 -s SUPPORT_ERRNO=0 -s MALLOC=emmalloc --output_eol=linux --preload-file=${CMAKE_SOURCE_DIR}/assets/@/assets/")

This is my command line output:
[4/4] Linking CXX executable WebGPUSynthesis.js
FAILED: WebGPUSynthesis.js
cmd.exe /C "cd . && C:\Apps\emsdk\upstream\emscripten\em++.bat -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS=png -pthread -s USE_PTHREADS -s SHARED_MEMORY=0 -O3 -DNDEBUG -s DISABLE_EXCEPTION_CATCHING=1 -s ASSERTIONS=0 -s WASM=1 -s USE_WEBGPU=1 -s NO_EXIT_RUNTIME=1 -s STRICT=0 -pthread -s USE_PTHREADS -s SHARED_MEMORY=0 -s ENVIRONMENT=web,worker -s TEXTDECODER=2 -s ABORTING_MALLOC=0 -s ALLOW_MEMORY_GROWTH=0 -s SUPPORT_ERRNO=0 -s MALLOC=emmalloc --output_eol=linux --preload-file=C:/Code/Misc/WASM_SYNTHESIS/assets/@/assets/ -s MAX_WEBGL_VERSION=2 -s FETCH=1 -s WASM_BIGINT=1 -s MODULARIZE=1 -s EXPORT_NAME=createQtAppInstance -s DISABLE_EXCEPTION_CATCHING=1 -pthread -s ALLOW_MEMORY_GROWTH -sASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js -s ERROR_ON_UNDEFINED_SYMBOLS=1 CMakeFiles/WebGPUSynthesis.dir/src/main.cpp.o CMakeFiles/WebGPUSynthesis.dir/src/PreCompiledHeader.cpp.o -o WebGPUSynthesis.js C:/Qt/6.5.0/wasm_multithread/lib/libQt6Core.a C:/Qt/6.5.0/wasm_multithread/lib/libQt6BundledZLIB.a C:/Qt/6.5.0/wasm_multithread/lib/libQt6BundledPcre2.a -lembind && cd ."
em++: warning: -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see WebAssembly/design#1271 [-Wpthreads-mem-growth]
wasm-ld: error: --shared-memory is disallowed by IMG_png.c.o because it was not compiled with 'atomics' or 'bulk-memory' features.
em++: error: 'C:/Apps/emsdk/upstream/bin\wasm-ld.exe -o WebGPUSynthesis.wasm CMakeFiles/WebGPUSynthesis.dir/src/main.cpp.o CMakeFiles/WebGPUSynthesis.dir/src/PreCompiledHeader.cpp.o C:/Qt/6.5.0/wasm_multithread/lib/libQt6Core.a C:/Qt/6.5.0/wasm_multithread/lib/libQt6BundledZLIB.a C:/Qt/6.5.0/wasm_multithread/lib/libQt6BundledPcre2.a -LC:\Apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten C:\Apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libSDL2_image_png.a C:\Apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libpng-mt.a C:\Apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libSDL2-mt.a C:\Apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libz.a C:\Apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\crtbegin.o --whole-archive -lfetch-mt -lembind-rtti --no-whole-archive -lGL-mt-webgl2 -lal -lhtml5 -lbulkmemory -lstubs -lnoexit -lc-mt -lemmalloc-mt-noerrno -lcompiler_rt-mt -lc++-mt-noexcept -lc++abi-mt-noexcept -lsockets-mt -lwebgpu_cpp-mt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr C:\Users\Grisha\AppData\Local\Temp\tmplclyditylibemscripten_js_symbols.so --import-memory --shared-memory --strip-debug --export-if-defined=main --export-if-defined=_emscripten_thread_init --export-if-defined=_emscripten_thread_exit --export-if-defined=_emscripten_thread_crashed --export-if-defined=_emscripten_tls_init --export-if-defined=pthread_self --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=_main_argc_argv --export=stackSave --export=stackRestore --export=stackAlloc --export=emscripten_dispatch_to_thread --export=_emscripten_thread_free_data --export=emscripten_main_runtime_thread_id --export=emscripten_main_thread_process_queued_calls --export=_emscripten_run_in_main_runtime_thread_js --export=emscripten_stack_set_limits --export=malloc --export=free --export=__wasm_call_ctors --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=2147483648 --global-base=1024' failed (returned 1)
ninja: build stopped: subcommand failed.

It looks as if the version of lib PNG (same goes for JPG) wasn't built with multithread support, and throwing a linker error. You can see up top I was trying to switch shared memory off (don't need it) but that didn't help.
Is there any way to get around this, or do I need to build my own version of libPNG to get this working?

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