Skip to content

WASM build fails due to missing main symbol when linking C libraries #37

@roninjin10

Description

@roninjin10

Problem

The WASM build (zig build wasm) fails with:

wasm-ld: undefined symbol: main

This happens because:

  1. The primitives dependency includes C libraries (BLST, C-KZG, BN254)
  2. These require linking with libc (-lc)
  3. WASI libc expects a main function entry point
  4. Even with entry = .disabled and -fno-entry, the linker still requires main

Current Workaround

Removed WASM from the default zig build step (commit 2d2119a). The WASM build is now only triggered explicitly via zig build wasm, but it still fails.

Potential Solutions

  1. Add a stub main function - Export a no-op main in src/root_c.zig when targeting WASI
  2. Use freestanding target - Switch from wasm32-wasi to wasm32-freestanding, but this may break C library compatibility
  3. Conditional C library linking - Only link crypto libraries when not targeting WASM (would reduce WASM functionality)
  4. Custom WASI reactor entry - Use _initialize instead of main for WASI reactor-style modules

References

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