Emscripten "shared memory ... but ... not enabled" pthreads error in CI
A threaded Emscripten build produces a wasm module with shared memory, which requires the atomics and bulk-memory features. If the build flags or the consuming runtime do not enable them, link or instantiation fails.
What this error means
emcc fails with "shared memory is enabled, but ... atomics ... not enabled", or the module errors at runtime because the host did not enable threads features.
wasm-ld: error: --shared-memory is disallowed by main.o because it was not compiled
with 'atomics' or 'bulk-memory' features
emcc: error: 'wasm-ld ...' failed (returned 1)Common causes
Pthreads enabled without the matching wasm features
Using -pthread/-sUSE_PTHREADS makes memory shared, which needs atomics and bulk-memory. Mismatched flags across objects cause the link to reject shared memory.
A subset of objects compiled without -pthread
Mixing objects compiled with and without -pthread leaves some without the required features, so wasm-ld disallows shared memory.
How to fix it
Compile and link all objects with pthreads
- Pass
-pthreadto every compile and the link command. - Set a pthread pool size so threads are available.
- Rebuild so all objects carry atomics and bulk-memory.
emcc -pthread -sPTHREAD_POOL_SIZE=4 main.c worker.c -o app.jsDrop pthreads if threads are not needed
If the threaded path is unintended, remove the pthread flags so the module uses ordinary linear memory.
How to prevent it
- Apply
-pthreadconsistently to every compile and the link. - Keep the runtime configured to enable threads features.
- Avoid mixing threaded and non-threaded objects in one module.