You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I write a C program which will send an HTTP request to a server and it can run successfully when compiling it to machine code.
When I try to use wasi-sdk to compile it, I encounter the following errors. It seems that wasi-sdk cannot find the socket library API. What should I do to compile it successfully? Thank you very much!
ubuntu:~/c-app$ /home/ubuntu/wasi-sdk-23.0/bin/clang --sysroot=/home/ubuntu/wasi-sdk-23.0/share/wasi-sysroot app.c -o app.wasm
app.c:24:9: error: call to undeclared function'socket'; ISO C99 and later do not support implicit functiondeclarations [-Wimplicit-function-declaration]
24 | sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);| ^
app.c:25:2: error: call to undeclared function'setsockopt'; ISO C99 and later do not support implicit functiondeclarations [-Wimplicit-function-declaration]
25 | setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&on, sizeof(int));| ^
app.c:25:2: note: did you mean 'getsockopt'?
/home/ubuntu/wasi-sdk-23.0/share/wasi-sysroot/include/wasm32-wasi/sys/socket.h:436:5: note: 'getsockopt' declared here
436 | int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict);| ^
app.c:32:5: error: call to undeclared function'connect'; ISO C99 and later do not support implicit functiondeclarations [-Wimplicit-function-declaration]
32 | if(connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == -1){
| ^
3 errors generated.
I suspect that what is happening here is that you are hitting a target that has not yet enabled support for wasi-sockets. This is actually more of a wasi-libc issue, since that is where the C definitions of those functions would get plumbed to the appropriate wasi-sockets calls. In fact, there's already an issue open on this where @dicej talks about a plan for a wasi-libc target that would support this: WebAssembly/wasi-libc#447.
I suggest we close this issue and ask for a status update there? If something is still broken, I can move this issue to that repository.
Sure. But I am curious that before the wasi-sockets or wasi-http APIs are implemented, is there any other way to run a C program which sends HTTP requests to other services on Wasm?
Hi, I write a C program which will send an HTTP request to a server and it can run successfully when compiling it to machine code.
When I try to use
wasi-sdk
to compile it, I encounter the following errors. It seems thatwasi-sdk
cannot find the socket library API. What should I do to compile it successfully? Thank you very much!The text was updated successfully, but these errors were encountered: