# Building box2d for wasm32

**URL:** <https://ziggit.dev/t/building-box2d-for-wasm32/9760>\
**Category:** Help\
**Tags:** build-system\
**Created:** [April 22, 2025, 8:02pm UTC](https://ziggit.dev/t/building-box2d-for-wasm32/9760 "2025-04-22T20:02:15Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![danielchooper](https://ziggit.dev/user_avatar/ziggit.dev/danielchooper/32/896_2.png) [@danielchooper](https://ziggit.dev/u/danielchooper)\
**Post date:** [May 16, 2025, 10:30pm UTC](https://ziggit.dev/t/building-box2d-for-wasm32/9760/10 "2025-05-16T22:30:00Z")

</div>

I was finally able to get zig to compile box2d for `wasm32-emscripten` using:

```sh
BOX2D_PATH=$HOME/box2d-3.1.0
BOX2D_SRC_FILES=($BOX2D_PATH/src/*.c(N))
zig build-lib $BOX2D_SRC_FILES \
-DBOX2D_DISABLE_SIMD \
-cflags -std=c17 -mbulk-memory -matomics -msimd128 -msse2 -- \
-I$BOX2D_PATH/include \
-lc -OReleaseFast --name box2d -static \
-target wasm32-emscripten -mcpu baseline \
-isystem $EMSDK/upstream/emscripten/cache/sysroot/include

```

The `-DBOX2D_DISABLE_SIMD` is required because it seems like zig’s SIMD headers don’t support wasm32?:

```zig
zig-macos-aarch64-0.13.0/lib/include/emmintrin.h:14:2: 
error: "This header is only meant to be used on x86 and x64 architecture"

box2d-3.1.0/src/contact_solver.c:527:10: note: in file included from box2d-3.1.0/src/contact_solver.c:527:
#include <emmintrin.h>

```

emcc is able to compile box2d with simd enabled.

```make
BOX2D_OBJ_FILES := $(notdir $(BOX2D_SRC_FILES:.c=.o))
emcc-box2d:
    emcc -mbulk-memory -matomics -msimd128 -msse2 -I$(BOX2D_PATH)/include -c $(BOX2D_SRC_FILES) && \
    emar qc libbox2d.a $(BOX2D_OBJ_FILES) && \
    emranlib libbox2d.a

```

If anyone knows how to compile SIMD for wasm32-emscripten, I’d appreciate your advice!

---

_[View the full topic](https://ziggit.dev/t/building-box2d-for-wasm32/9760)._
