我将使用Duktape进行ARM 32/64平台的javascript评估。 我想建立Duktape只针对特定平台和建筑,不适用于所有范围。
看来,我可以成功构建它:
python tools/configure.py \
--source-directory src-input \
--platform linux \
--architecture arm32 \
--config-metadata config/ \
--option-file arm32_config.yaml \
--output-directory /tmp/arm32
arm32_config.yaml :
DUK_USE_32BIT_PTRS: true
DUK_USE_64BIT_OPS: false
DUK_USE_FATAL_HANDLER: false
通常建立通行证。那太棒了!
在Raspberry Pi上(仅用于测试):
我有 hello.c :
#include "duktape.h"
int main(int argc, char *argv[]) {
duk_context *ctx = duk_create_heap_default();
duk_eval_string(ctx, "print('Hello world!');");
duk_destroy_heap(ctx);
return 0;
}
和 Makefile.hello 文件:
DUKTAPE_SOURCES = src/arm32/duktape.c
# Compiler options are quite flexible. GCC versions have a significant impact
# on the size of -Os code, e.g. gcc-4.6 is much worse than gcc-4.5.
CC = gcc
CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer
CCOPTS += -I./src/arm32 # for combined sources
CCLIBS = -lm
CCOPTS += -DUK_USE_32BIT_PTRS
CCOPTS += -DUK_USE_64BIT_OPS
CCOPTS += -DUK_USE_FATAL_HANDLER
# For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer
hello: $(DUKTAPE_SOURCES) hello.c
$(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) hello.c $(CCLIBS)
它也有效!
但是,当我尝试启动程序 ./ hello 时,我总是收到: 细分错误
请指出我的错误?我错过了什么? 提前谢谢!
ps:gcc版本4.9.2(Raspbian 4.9.2-10)
答案 0 :(得分:1)
您最有可能遇到的主要问题是您正在使用Duktape master(将成为2.0.0版本),它不再提供内置的“print()”绑定。这会导致抛出错误。
该错误未被捕获,因为您没有包含eval调用的受保护调用,因此发生致命错误。由于您没有提供致命的错误处理程序(在duk_create_heap()或通过DUK_USE_FATAL_HANDLER),导致默认的致命错误行为导致故意的段错误(这是调试器可以附加的)。
所以最简单的解决方法是定义一个print()绑定,并为eval添加一个致命的错误处理程序和/或一个受保护的调用。这是添加print()绑定(在执行eval之前)的示例:
static duk_ret_t native_print(duk_context *ctx) {
duk_push_string(ctx, " ");
duk_insert(ctx, 0);
duk_join(ctx, duk_get_top(ctx) - 1);
printf("%s\n", duk_safe_to_string(ctx, -1));
return 0;
}
/* ... before doing eval(): */
duk_push_c_function(ctx, native_print, DUK_VARARGS);
duk_put_global_string(ctx, "print");
其他次要评论:
-DUK_USE_FATAL_HANDLER
定义预处理器值UK_USE_FATAL_HANDLER
。