Open GrigoryGraborenko opened 1 year ago
It looks like tools/ports/sdl2_image.py
need to be updated to have -mt
variants, like tools/ports/sdl2.py
.
FWIW downgrading to emsdk 3.0.1
worked for me. I used the emscripten/emsdk:3.0.1
Docker image in the end.
Looks like this issue can be fixed by swapping LDFLAGS -lpng
to -lpng-mt
. Thanks to @noamr for pointing that out!
Just faced the same problem. Is there a workaround? How to use the "-lpng-mt" flag in a CMakeLists.txt? Here is my list of flags: `set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL_TTF=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL_IMAGE=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_FREETYPE=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_ZLIB=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_LIBPNG=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s SDL2_IMAGE_FORMATS=\"[png]\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --preload-file ./fonts")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s STACK_SIZE=20MB")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s INITIAL_MEMORY=100MB")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_DISABLE_EXCEPTION_CATCHING")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXPORTED_RUNTIME_METHODS=\"['cwrap','ccall']\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s LLD_REPORT_UNDEFINED") `
Hi, i'm trying to compile a wasm application (with pthreads) to support PNG:
--shared-memory is disallowed by IMG_png.c.o because it was not compiled with 'atomics' or 'bulk-memory' features
Using SDL2 and SDL2 Image:
EM_LINKER_FLAGS = -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' --preload-file ./assets@/assets
Any ideas?
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 https://github.com/WebAssembly/design/issues/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_tothread --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?