WASM的编译器定义的宏是什么?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
请参阅 this 。
编辑:
EMCC -E -DM-< /dev/null
给出了与WASM相关的其他定义:
我不确定它们是由Clang还是由Emscripten添加的。
Try:
See this.
Edit:
emcc -E -dM - < /dev/null
Gives other defines related to wasm:
I'm not sure if they are added by clang or by emscripten.
根据@jonathan Leffler的评论,似乎没有一个标准的宏,该宏是在编译器之间定义的。
我目前与不同编译器合作的解决方案是为WASM创建一个定义宏的单独的构建作业。对于
GCC
和clang
,它传递了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
andclang
, 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.