我正在使用Bazel (5.2.0)来构建一个emscripten应用程序。我的设置如下:
main.cpp
#include "emscripten.h"
#include <iostream>
int main(int argc, char **argv) {
throw std::runtime_error("error!");
}BUILD.bazel
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
cc_binary(
name = "index",
srcs = ["main.cpp"],
copts = [
"-Wno-unused-variable",
"-Wno-unused-but-set-variable",
"-Wno-unused-function",
],
data = ["index.html"],
linkopts = [
"-s USE_GLFW=3",
"-s USE_WEBGPU=1",
"-s WASM=1",
"-s ALLOW_MEMORY_GROWTH=1",
"-s NO_EXIT_RUNTIME=0",
"-s ASSERTIONS=1",
"-s EXCEPTION_CATCHING_ALLOWED=[..]",
],
tags = ["manual"],
)
wasm_cc_binary(
name = "index-wasm",
cc_target = ":index",
)WORKSPACE.bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "emsdk",
strip_prefix = "emsdk-311acff345fd71dcfe5f350653cec466ee7e3fbc/bazel",
url = "https://github.com/emscripten-core/emsdk/archive/311acff345fd71dcfe5f350653cec466ee7e3fbc.tar.gz",
)
load("@emsdk//:deps.bzl", emsdk_deps = "deps")
emsdk_deps()
load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
emsdk_emscripten_deps(emscripten_version = "3.1.13")当构建我的应用程序时,我会得到以下错误:
main.cpp:11:5: error: cannot use 'throw' with exceptions disabled
throw std::runtime_error("error!");
^我添加了"-s EXCEPTION_CATCHING_ALLOWED=[..]",已经到了链接选项,但这似乎没有帮助。
知道如何使用Bazel在Emscripten中启用异常吗?
发布于 2022-06-23 04:10:52
您应该将启用C++异常选项设置为,将设置为,将启用目标-C异常设置为是。如果您还有这个问题,那么refer
https://stackoverflow.com/questions/72631196
复制相似问题