wasmerio / wasmer-c-api

Example of the C API to embed the Wasmer runtime
https://wasmerio.github.io/wasmer/c/runtime-c-api/
80 stars 10 forks source link

Non-WASI example fails due to imported func not being found (Wasmer 1.0.0) #17

Open helje5 opened 3 years ago

helje5 commented 3 years ago

When running the non-WASI example, the invocation fails due to the import failing.

Steps I took:

zMBP20:wasmer-c-api helge$ cc -I$HOME/.wasmer/include -L$HOME/.wasmer/lib wasmer-c-api-example.c -o test-simple -lwasmer
zMBP20:wasmer-c-api helge$ ./test-simple 
Compile result:  2
Error len: `125`
Error str: `Error while importing "env"."print_str": unknown import. Expected Function(FunctionType { params: [I32, I32], results: [] })`
Assertion failed: (compile_result == WASMER_OK), function main, file wasmer-c-api-example.c, line 110.
Abort trap: 6
MarkMcCaskey commented 3 years ago

Thanks for the ping: this repo is pretty out of date so a lot of things may not work right... I tried to reproduce and I found that on x86_64 macos it worked with libwasmer.a but not with libwasmer.dylib

clang -I$HOME/.wasmer/include -L$HOME/.wasmer/lib wasmer-c-api-example.c -o test-simple -lwasmer
➜  wasmer-c-api git:(master) ✗ ./test-simple
Compile result:  1
Hello, World!
Call result:  1

I'm not sure why it wasn't working with the dylib:

./test-simple
dyld: Library not loaded: @rpath/libwasmer.dylib
  Referenced from: /Users/mark/temp/wasmer-c-api/./test-simple
  Reason: image not found
[1]    69683 abort      ./test-simple
helje5 commented 3 years ago

I'm not using the dylib. The steps I mentioned repro for me all the time.

(Presumably it doesn't work for you because you don't have ~/.wasmer/lib in your DYLIB path.)