WASM的编译器定义的宏是什么?

发布于 2025-02-12 15:13:08 字数 327 浏览 0 评论 0原文

clang和/或gcc在编译WASM后端时定义的宏是什么?

为了澄清,可以使用宏来编写特定于平台的代码。编译器可以定义这样的定义:

#if _WIN32
// Windows-specific code
#elif __linux__
// Linux-specific code
#elif __APPLE__
// macOS-specific code
#else
#error Unsupported platform
#endif

我想执行与潜在后端之一指定WebAssembly相同的事情。

What is the macro that clang and/or gcc would define when compiling for a WASM backend?

To clarify, one can write platform-specific code using macros the compiler defines like so:

#if _WIN32
// Windows-specific code
#elif __linux__
// Linux-specific code
#elif __APPLE__
// macOS-specific code
#else
#error Unsupported platform
#endif

I would like to do the same thing specifying WebAssembly as one of the potential backends.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假扮的天使 2025-02-19 15:13:08

尝试:

__EMSCRIPTEN__

请参阅 this

编辑:

EMCC -E -DM-< /dev/null

给出了与WASM相关的其他定义:

#define __wasm 1
#define __wasm32 1
#define __wasm32__ 1
#define __wasm__ 1

我不确定它们是由Clang还是由Emscripten添加的。

Try:

__EMSCRIPTEN__

See this.

Edit:

emcc -E -dM - < /dev/null

Gives other defines related to wasm:

#define __wasm 1
#define __wasm32 1
#define __wasm32__ 1
#define __wasm__ 1

I'm not sure if they are added by clang or by emscripten.

萌无敌 2025-02-19 15:13:08

根据@jonathan Leffler的评论,似乎没有一个标准的宏,该宏是在编译器之间定义的。

我目前与不同编译器合作的解决方案是为WASM创建一个定义宏的单独的构建作业。对于GCCclang,它传递了flag -d__-wasm __来定义a __ WASM __ __宏。

在我的设置中,我只是更改环境变量,而构建脚本选择了适当的构建标志。

As per @Jonathan Leffler's comment, there does not appear to be a standard macro that is defined across compilers.

My current solution for working with different compilers is to create a separate build job for WASM that defines a macro. For gcc and clang, it passes the flag -D__WASM__ to define a __WASM__ macro.

In my setup, I just change an environment variable and my build script selects the appropriate build flags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文