SDL2 不想在 emscripten 项目中使用 -pthread 标志进行编译。为什么?如何解决这个问题?
CMake-config
set(USE_FLAGS "-sUSE_ZLIB=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS=['png,jpg'] -O3 -g -sWASM_WORKERS -sUSE_PTHREADS=1" CACHE STRING "Compilation flags" FORCE)
set(LINKING_FLAGS "--preload-file ${ASSETS_PATH}/assets@/assets -sFULL_ES2 -sWASM=1 -sFETCH=1 -sEXIT_RUNTIME=1 -sALLOW_MEMORY_GROWTH=1 -sEXPORTED_FUNCTIONS=['_main','_photoTaken','_malloc','_setNotificationToken','_interceptPushNotification','stackSave','stackRestore','stackAlloc'] -sEXPORTED_RUNTIME_METHODS=[cwrap] -sFORCE_FILESYSTEM=1 -lidbfs.js -O3 -g -sAUDIO_WORKLET=1 -sWASM_WORKERS -sASYNCIFY -sASYNCIFY_STACK_SIZE=131072 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS=['png,jpg'] -sWEBAUDIO_DEBUG=1 -sUSE_PTHREADS=1 -sPTHREAD_POOL_SIZE=8 -sPROXY_TO_PTHREAD" CACHE STRING "Linking flags" FORCE)
错误
assert 'EM_CACHE_IS_LOCKED' not in os.environ, f'attempt to lock the cache while a parent process is holding the lock ({reason})'
AssertionError: attempt to lock the cache while a parent process is holding the lock (sysroot/lib/wasm32-emscripten/libSDL2.a)
em++: error: subprocess 1/19 failed (returned 1)! (cmdline: /../../emsdk/upstream/emscripten/emcc -c /../../emsdk/upstream/emscripten/cache/ports/sdl2_image/SDL_image-release-2.6.0/IMG.c -o /Users/olegparamonov/emsdk/upstream/emscripten/cache/ports-builds/sdl2_image/IMG.c.o -g -sSTRICT -Werror -O2 -I/../../emsdk/upstream/emscripten/cache/ports/sdl2_image/SDL_image-release-2.6.0 -O2 -sUSE_SDL=2 -Wno-format-security -DLOAD_JPG -DLOAD_PNG -sUSE_LIBPNG -sUSE_LIBJPEG)
您需要首先从 sdl2 构建所需的一切,例如:
embuilder 构建 sdl2 sdl2_ttf sdl2_image sdl2_image_jpg sdl2_image_png
这解决了我的问题。