ハック
すでに結合があるため、ヘッダーファイルでの条件付き定義だけでなく、散乱libとヘッダの場所を失敗していたように私には発生していました。十分に...私はコマンドラインでJS_HAS_CTYPESを定義しようとしましたが、それがうまくいくかどうかは確かに十分ではありませんでした。
私はSpiderMonkeyシェルに独自のmakefileがあり、キャプチャしようとしている機能に既にアクセスできていると判断しました。js.cppの名前をjs.cpp.tmpに変更し、場所は、ほとんど働いた。
ファイルがコンパイルされていて、アプリケーション実行時に実行時リンクエラーがスローされませんでしたが、コード(JSNativeObject 'ctypes)はJS_InitCTypesClassにほぼ完全に失敗しました。私のリンクエラーが長い間忘れられていたのを見て、私はすぐにコンパイルコードをスワイプすることができるかどうかを確認するためにmakeの出力を調べました...私たちはビンゴを持っています!
コンパイル
は元の標的にシェル/ js.cppを復元した後、私はSpiderMonkeyのルートのソースディレクトリにHELLO.CPPを移動した相対パスを修正し始めましたmakefileによって作成され、アプリケーションに存在感や依存性を明らかに持たない構造体の削除を実行します。
次のコマンドが動作バイナリをレンダリングするように見えるが、著者はこのリストの正確性や完全性について何らの親和性を与えることはできません。上記
c++ -o hello.o -c -Idist/system_wrappers_js -include config/gcc_hidden.h \
-DEXPORT_JS_API -DOSTYPE=\"Linux3.2\" -DOSARCH=Linux -I. -Idist/include \
-Idist/include/nsprpub -I/usr/include/nspr -fPIC -fno-rtti \
-fno-exceptions -Wall -Wpointer-arith -Woverloaded-virtual -Wsynth \
-Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align \
-Wno-invalid-offsetof -Wno-variadic-macros -Werror=return-type -pedantic \
-Wno-long-long -fno-strict-aliasing -pthread -pipe -DNDEBUG -DTRIMMED -Os \
-freorder-blocks -fomit-frame-pointer -DJS_HAS_CTYPES -DMOZILLA_CLIENT \
-include js-confdefs.h -MD -MF .deps/hello.pp hello.cpp;
c++ -o hello -fno-rtti -fno-exceptions -Wall -Wpointer-arith \
-Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy \
-Wno-non-virtual-dtor -Wcast-align -Wno-invalid-offsetof \
-Wno-variadic-macros -Werror=return-type -pedantic \
-Wno-long-long -fno-strict-aliasing -pthread -pipe -DNDEBUG \
-DTRIMMED -Os -freorder-blocks -fomit-frame-pointer hello.o \
-lpthread -Wl,-rpath-link,/bin -Wl,-rpath-link,/usr/local/lib \
-Ldist/bin -Ldist/lib -L/usr/lib -lplds4 -lplc4 -lnspr4 \
-lpthread -ldl editline/libeditline.a libjs_static.a -ldl;
二つのコマンドは、ルートソースディレクトリに保存された「mkhello」という名前の実行可能なシェルスクリプトに入れました。私はそれが2段階のコンパイル方法で収集することができるものから、
。どのような理由で私はわかりませんが、説明は非常に教育的です。思考?
EDIT「two stage compilation method」の説明については、下記のコメントを参照してください。
コード:HELLO.CPP
/*
* This define is for Windows only, it is a work-around for bug 661663.
*/
#ifdef _MSC_VER
# define XP_WIN
#endif
/* Include the JSAPI header file to get access to SpiderMonkey. */
#include "jsapi.h"
/* The class of the global object. */
static JSClass global_class = {
"global", JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
JSCLASS_NO_OPTIONAL_MEMBERS
};
/* The error reporter callback. */
void reportError(JSContext *cx, const char *message, JSErrorReport *report)
{
fprintf(stderr, "%s:%u:%s\n",
report->filename ? report->filename : "<no filename=\"filename\">",
(unsigned int) report->lineno,
message);
}
int main(int argc, const char *argv[])
{
/* JSAPI variables. */
JSRuntime *rt;
JSContext *cx;
JSObject *global;
/* Create a JS runtime. You always need at least one runtime per process. */
rt = JS_NewRuntime(8 * 1024 * 1024);
if (rt == NULL)
return 1;
/*
* Create a context. You always need a context per thread.
* Note that this program is not multi-threaded.
*/
cx = JS_NewContext(rt, 8192);
if (cx == NULL)
return 1;
JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
JS_SetVersion(cx, JSVERSION_LATEST);
JS_SetErrorReporter(cx, reportError);
/*
* Create the global object in a new compartment.
* You always need a global object per context.
*/
global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
if (global == NULL)
return 1;
/*
* Populate the global object with the standard JavaScript
* function and object classes, such as Object, Array, Date.
*/
if (!JS_InitStandardClasses(cx, global))
return 1;
/* Populate the global object with the ctypes object. */
if (!JS_InitCTypesClass(cx, global))
return NULL;
/*
/* Your application code here. This may include JSAPI calls
* to create your own custom JavaScript objects and to run scripts.
*
* The following example code creates a literal JavaScript script,
* evaluates it, and prints the result to stdout.
*
* Errors are conventionally saved in a JSBool variable named ok.
*/
char *script = "ctypes.open";
jsval rval;
JSString *str;
JSBool ok;
const char *filename = "noname";
uintN lineno = 0;
ok = JS_EvaluateScript(cx, global, script, strlen(script),
filename, lineno, &rval);
if (rval == NULL | rval == JS_FALSE)
return 1;
str = JS_ValueToString(cx, rval);
printf("%s\n", JS_EncodeString(cx, str));
/* End of your application code */
/* Clean things up and shut down SpiderMonkey. */
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
JS_ShutDown();
return 0;
}
結論
$ ./mkhello
# ...
# error free garbage scrolls....
$ ./hello
function open() {
[native code]
}
はSpiderMonkeyの埋め込みにJS-ctypesのを提供するために、この例では、次のとおり。これらの手順を順番に再作成する必要はありませんが、現在の観点からすることを強くお勧めします。
それは1つの気高い旅行でした! –
-lol 'libary'私はそこにその1つを残しています!私は子供だったので、それを聞いていない。 –