c - 当clang编译到目标wasm时,函数声明返回错误
问题描述
我试图wasm
从 c 程序生成文件。
clang test.c --target=wasm32-unknown-unknown-wasm -nostartfiles -nostdlib -Wl,--no-entry -Wl,--export-all -o test.wasm
文件内容test.c
如下
extern void __VERIFIER_error(void);
extern void __VERIFIER_assume(int);
void __VERIFIER_assert(int cond) {
if (!(cond)) {
ERROR: __VERIFIER_error();
}
return;
}
int __VERIFIER_nondet_int();
int test() {
int x = 1;
int y = 0;
while (y < 1000 && __VERIFIER_nondet_int()) {
x = x + y;
y = y + 1;
}
__VERIFIER_assert(x >= y);
return 0;
}
遇到以下错误信息:
clang test.c --target=wasm32-unknown-unknown-wasm -nostartfiles -nostdlib -Wl,--no-entry -Wl,--export-all -o test.wasm
wasm-ld: error: /tmp/test-e520f3.o: undefined symbol: __VERIFIER_error
wasm-ld: error: /tmp/test-e520f3.o: undefined symbol: __VERIFIER_nondet_int
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
我已将文件内容更新如下:
extern "C" void __VERIFIER_error(void);
extern "C" void __VERIFIER_assume(int);
extern "C" void __VERIFIER_assert(int cond) {
if (!(cond)) {
ERROR: __VERIFIER_error();
}
return;
}
extern "C" int __VERIFIER_nondet_int();
int test() {
int x = 1;
int y = 0;
while (y < 1000 && __VERIFIER_nondet_int()) {
x = x + y;
y = y + 1;
}
__VERIFIER_assert(x >= y);
return 0;
}
遇到以下错误信息,如何摆脱此类错误。任何人都可以在这方面指导。
test/test.c:1:8: error: expected identifier or '('
extern "C" void __VERIFIER_error(void);
^
test/test.c:2:8: error: expected identifier or '('
extern "C" void __VERIFIER_assume(int);
^
test/test.c:3:8: error: expected identifier or '('
extern "C" void __VERIFIER_assert(int cond) {
^
test/test.c:9:8: error: expected identifier or '('
extern "C" int __VERIFIER_nondet_int();
^
test/test.c:13:24: warning: implicit declaration of function '__VERIFIER_nondet_int' is invalid in C99 [-Wimplicit-function-declaration]
while (y < 1000 && __VERIFIER_nondet_int()) {
^
test/test.c:17:5: warning: implicit declaration of function '__VERIFIER_assert' is invalid in C99 [-Wimplicit-function-declaration]
__VERIFIER_assert(x >= y);
^
2 warnings and 4 errors generated.
解决方案
您有两个没有定义的函数。您不链接任何库或其他目标文件。所以链接器没有找到它们并发出错误消息。
推荐阅读
- python - 即使一切似乎都是正确的,带有 Django 的 Dash App 也会出现 NolayoutExeption 错误
- php - Symfony 和 nginx - 调用 API 时出现 502 Bad Gateway 错误
- kubernetes - 使用 envFrom 字段时出现 Argo Workflow 错误
- asp.net-core - 如何在 Target 框架名字对象类库中添加 System.web.dll?
- r - R循环在多个栅格上执行相同的任务?
- javascript - 使用 css 设置 Javascript 警报框样式
- google-bigquery - BigQuery - UDF 在视图中使用时返回 LEFT JOIN 错误
- laravel - 我的 laravel 应用程序最喜欢的功能
- python - Azure Data Lake + Python:身份验证失败
- elasticsearch - 有没有办法将数据(csv 数据)导入 winlogbeat kibana 仪表板?