diff --git a/w2c2/c.c b/w2c2/c.c index c3fbcff..d470bbf 100644 --- a/w2c2/c.c +++ b/w2c2/c.c @@ -4656,6 +4656,8 @@ wasmCWriteModuleHeader( fprintf(file, "#ifndef %s_H\n", moduleName); fprintf(file, "#define %s_H\n\n", moduleName); + fputs("#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n", file); + wasmCWriteBaseInclude(file); wasmCWriteModuleDeclarations(file, module, moduleName, pretty, debug, multipleModules); fprintf( @@ -4671,6 +4673,8 @@ wasmCWriteModuleHeader( moduleName ); + fputs("#ifdef __cplusplus\n}\n#endif\n\n", file); + fprintf(file, "#endif /* %s_H */\n\n", moduleName); if (fclose(file) != 0) { diff --git a/w2c2/w2c2_base.h b/w2c2/w2c2_base.h index 286bdf5..2567838 100644 --- a/w2c2/w2c2_base.h +++ b/w2c2/w2c2_base.h @@ -11,6 +11,10 @@ #include +#ifdef __cplusplus +extern "C" { +#else + #ifndef __bool_true_false_are_defined typedef enum bool { false = 0, @@ -18,6 +22,8 @@ typedef enum bool { } bool; #endif +#endif + typedef unsigned char U8; typedef signed char I8; @@ -903,4 +909,8 @@ wasmTableFree( #define TF(table, index, t) ((t)((table).data[index])) +#ifdef __cplusplus +} +#endif + #endif /* W2C2_BASE_H */ diff --git a/wasi/wasi.h b/wasi/wasi.h index ea17181..cfa35fd 100644 --- a/wasi/wasi.h +++ b/wasi/wasi.h @@ -24,6 +24,10 @@ typedef long ssize_t; #include #endif +#ifdef __cplusplus +extern "C" { +#endif + typedef struct WasiFileDescriptor { int fd; DIR* dir; @@ -637,4 +641,8 @@ wasiFromNativePath( char *path ); +#ifdef __cplusplus +} +#endif + #endif /* W2C2_WASI_H */ diff --git a/wasi/win32.h b/wasi/win32.h index 0bb3218..528e5f4 100644 --- a/wasi/win32.h +++ b/wasi/win32.h @@ -4,6 +4,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct dirent { long d_ino; unsigned short d_reclen; @@ -35,4 +39,8 @@ struct DIR { HANDLE handle; }; +#ifdef __cplusplus +} +#endif + #endif /* W2C2_WASI_WIN32_H */