wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

Error when compiling the tcp_client/server example

Open qmyyxtl opened this issue 3 years ago • 6 comments
trafficstars

I see a new pull_requests for the socket_api so i want to comile the example and test. But when I use cmake to complie the code, there is an error /wasm-micro-runtime/samples/network/wasm-src/tcp_client.c:14:10: fatal error: 'wasi_socket_ext.h' file not found #include <wasi_socket_ext.h> how can i fix it?

qmyyxtl avatar Mar 09 '22 14:03 qmyyxtl

I compile the sample use the command

cmake -DWASI_SDK_PREFIX=/opt/wasi-sdk -DCMAKE_TOOLCHAIN_FILE=/home/yxz/wasm_tools/wasm-pr/wasm-micro-runtime/wamr-sdk/app/wasi_toolchain.cmake -DCMAKE_SYSROOT=/opt/wasi-sdk/share/wasi-sysroot ..
make

And the result shows wasi_socket_ext.h file not found

qmyyxtl avatar Mar 09 '22 14:03 qmyyxtl

Cannot repeat it locally. Only some general suggestions:

  • please checkout to the latest commit d0a5ce739cfee3d6d5553e9c7d21fe91d9845b6f and the branch dev/socket_api. It is still an experiment feature.
  • a shorter command like $cmake -DWASI_SDK_DIR=/opt/wasi-sdk .. or even $cmake .. is fine.

lum1n0us avatar Mar 09 '22 22:03 lum1n0us

It can work now. I rebuild it. But some eror happens when i try to run the wasm file. If i run the executable file tcp_server and tcp_client, it works and can receive the massage. But when I want to run tcp_server.wasm use

../../../product-mini/platforms/linux/build/iwasm tcp_server.wasm

It comes to an error

WASM module load failed: invalid section id

qmyyxtl avatar Mar 10 '22 04:03 qmyyxtl

@qmyyxtl please build iwasm with libc-wasi and lib-pthread enabled: cmake .. -DWAMR_BUILD_LIB_PTHREAD=1, thanks. We also uploaded PR #1040 to refine to sample and document, the user experience should be better after it is merged.

wenyongh avatar Mar 10 '22 04:03 wenyongh

@wenyongh thanks a lot, I follow the PR README and build it. It seems that building still has some problems, but the tcp_server.wasm and tcp_client.wasm can be run now. The cmake result:

[ 98%] Performing install step for 'wasm-app'
Error copying file "tcp_client.wasm.dump" to "/home/yxz/wasm_tools/wasm-pr/wasm-micro-runtime/samples/socket-api/build".
Error copying file "tcp_server.wasm.dump" to "/home/yxz/wasm_tools/wasm-pr/wasm-micro-runtime/samples/socket-api/build".
make[2]: *** [CMakeFiles/wasm-app.dir/build.make:102: wasm-app-prefix/src/wasm-app-stamp/wasm-app-install] Error 1
make[1]: *** [CMakeFiles/Makefile2:195: CMakeFiles/wasm-app.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

I notice that wabt is required but I havn't downloaded it yet. Is it the reason for the error or not? Although I think it doesn't matter for running

qmyyxtl avatar Mar 10 '22 05:03 qmyyxtl

WABT is used to examine that the socket APIs are all bridged to imported ones. Please feel free to skip that by changing CMakeLists.txt.

lum1n0us avatar Mar 10 '22 05:03 lum1n0us