wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

ERROR:undefined reference to `wasmtime_val_copy

Open Boring545 opened this issue 1 year ago • 3 comments

I attempted to compile wasmtime and its C API on a RISC-V 64 platform. The steps are as follows:

  1. Clone the Wasmtime Repository and Compile:

    git clone https://github.com/bytecodealliance/wasmtime.git
    cd wasmtime
    cargo build --release -p wasmtime-c-api
    
  2. Copy the Compiled Results:

    • The .a and .so files are located in wasmtime/target/release.
    • The header files are located in wasmtime/crates/c-api/include.
    sudo cp libwasmtime.a /usr/local/lib/
    sudo cp libwasmtime.so /usr/local/lib/
    sudo cp -r /home/zjq/build_factory/wasmtime/wasmtime/crates/c-api/include/* /usr/local/include/
    
  3. Compile a Package (kpt) Using lwasmtime:

    git clone https://github.com/kptdev/kpt.git
    cd kpt
    go build -v
    
# github.com/GoogleContainerTools/kpt
/home/zjq/riscv_istio_test/go_golang/go/pkg/tool/linux_riscv64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-2768106579/000011.o: in function `_cgo_a67a9a099c04_Cfunc_wasmtime_val_copy':
/tmp/go-build/cgo-gcc-prolog:250:(.text+0xcdc): undefined reference to `wasmtime_val_copy'
/usr/bin/ld: /tmp/go-link-2768106579/000021.o: in function `_cgo_a67a9a099c04_Cfunc_wasmtime_context_add_fuel':
/tmp/go-build/cgo-gcc-prolog:74:(.text+0x198): undefined reference to `wasmtime_context_add_fuel'
/usr/bin/ld: /tmp/go-link-2768106579/000021.o: in function `_cgo_a67a9a099c04_Cfunc_wasmtime_context_consume_fuel':
/tmp/go-build/cgo-gcc-prolog:94:(.text+0x2e0): undefined reference to `wasmtime_context_consume_fuel'
/usr/bin/ld: /tmp/go-link-2768106579/000021.o: in function `_cgo_a67a9a099c04_Cfunc_wasmtime_context_fuel_consumed':
/tmp/go-build/cgo-gcc-prolog:114:(.text+0x3de): undefined reference to `wasmtime_context_fuel_consumed'
/usr/bin/ld: /tmp/go-link-2768106579/000025.o: in function `_cgo_a67a9a099c04_Cfunc_wasmtime_val_delete':
/tmp/go-build/cgo-gcc-prolog:210:(.text+0x5ea): undefined reference to `wasmtime_val_delete'
collect2: error: ld returned 1 exit status

Boring545 avatar Jul 27 '24 10:07 Boring545

I couldn't find functions like wasmtime_val_copy in these header files, but I did find:


WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v);
WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*);

Is it possible that the version of c-api I compiled is too new, causing these APIs to be removed?

Boring545 avatar Jul 27 '24 10:07 Boring545

I don’t know the reason for your issue, but if it helps, here are the PRs that renamed/replaced those functions:

https://github.com/bytecodealliance/wasmtime/pull/7298/files

https://github.com/bytecodealliance/wasmtime/pull/8451/files

primoly avatar Jul 27 '24 18:07 primoly

Are you sure that the Wasmtime C API was built for RISC-V? If you only executed cargo build --release -p wasmtime-c-api then that would build it for the host platform, which is probably not RISC-V (but I could be wrong)

alexcrichton avatar Jul 29 '24 14:07 alexcrichton

I'm going to close this as it's been inactive for some time and the suspicion is that the library was built for the wrong target.

alexcrichton avatar Feb 25 '25 17:02 alexcrichton