给定一个简单的gcc
命令,如下所示:
gcc quickrb.c -o main -L /usr/local/lib/quickjs -I /usr/local/lib/quickjs -l quickjs
我正在尝试extconf.rb
使用mkmf
. 目前我有:
require 'mkmf'
dir_config('quickjs', '/usr/local/lib/quickjs', '/usr/local/include/quickjs')
abort('missing "quickjs.h"') unless find_header('quickjs/quickjs.h')
abort('missing JS_NewRuntime') unless find_library('quickjs', 'JS_NewRuntime', 'quickjs/quickjs.h')
abort('missing JS_NewContext') unless find_library('quickjs', 'JS_NewContext', 'quickjs/quickjs.h')
create_makefile('quickrb/quickrb')
这失败了:
checking for quickjs/quickjs.h... yes
checking for JS_NewRuntime() in -lquickjs... no
missing JS_NewRuntime
我不确定如何处理。如果没有find_library
Makefile 生成的调用,但是在编译时会失败:
dyld: Symbol not found: _JS_NewRuntime
注意:
这是我的示例quickrb.c
文件:
#include <quickjs/quickjs.h>
#include <ruby.h>
#include <stdio.h>
#include <strings.h>
void Init_quickrb()
{
const char *filename = "runtime";
const char *script = "3 + 4";
const size_t length = strlen(script);
JSRuntime *runtime = JS_NewRuntime();
JSContext *context = JS_NewContext(runtime);
JSValue value = JS_Eval(context, script, length, filename, JS_EVAL_TYPE_GLOBAL);
const char *result = JS_ToCString(context, value);
printf("%s = %s\n", script, result);
JS_FreeCString(context, result);
JS_FreeContext(context);
JS_FreeRuntime(runtime);
}