Making sure the c compiler knows about standard libraries.
I'm trying to compile the duktape project to wasm to see if I can stuff it in a canister. I'm using the basic reverse.c example but I moved over the duktape.h and duktape.c files into the directory and changed the function to try to call something out of this. It turns out that the reason it can't compile is that it can't see the standard libraries for some reason.
root@ad0ec66809cb:/usr/src/examples/c/reverse# wcc reverse.c
In file included from reverse.c:1:
In file included from ./duktape.h:196:
./duk_config.h:865:10: fatal error: 'time.h' file not found
#include <time.h>
^~~~~~~~
1 error generated.
time.h is in /usr/include. Do I need to do something to tell the compiler to look there?
I'm currently running clang-11 --target=wasm32 -c -O reverse.c
The file is below(I'm expecting some type errors once I get past the imports):
#include "duktape.h"
#define WASM_IMPORT(m,n) __attribute__((import_module(m))) __attribute__((import_name(n)));
#define WASM_EXPORT(n) asm(n) __attribute__((visibility("default")))
int dfn_ads(void) WASM_IMPORT("ic0", "msg_arg_data_size");
void dfn_adc(void *, int, int) WASM_IMPORT("ic0", "msg_arg_data_copy");
void dfn_reply_append(void *, int) WASM_IMPORT("ic0", "msg_reply_data_append");
void dfn_reply(void) WASM_IMPORT("ic0", "msg_reply");
void dfn_print(void *, int) WASM_IMPORT("ic0", "debug_print");
void go() WASM_EXPORT("canister_update go");
void go() {
char buf[128];
int sz = dfn_ads();
dfn_adc(buf, 0, sz);
// Encoded string: "DIDL" 0 1 0x71 LEB128(length) data
// So offset 7 holds string length (for short strings).
int n = buf[7];
duk_context *ctx = duk_create_heap_default();
duk_eval_string(ctx, "'a string'");
const char *str;
str = duk_get_string(ctx, -3);
dfn_print(str);
dfn_reply_append(str, 8);
dfn_reply();
}
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.