Javascript 编译嵌入式SpiderMonkey程序时出错
好的,我使用命令Javascript 编译嵌入式SpiderMonkey程序时出错,javascript,c++,static-libraries,header-files,spidermonkey,Javascript,C++,Static Libraries,Header Files,Spidermonkey,好的,我使用命令wget下载了SpiderMonkey源代码http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz并将其解压缩。然后,我通过执行以下命令成功地构建了包含文件和静态库: autoconf2.13 /configure--prefix=~/js--disable shared js make make-install 现在,我尝试使用命令g++-I/home/aaditmshah/js/include/js-L/hom
wget下载了SpiderMonkey源代码http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz
并将其解压缩。然后,我通过执行以下命令成功地构建了包含文件和静态库:
autoconf2.13
/configure--prefix=~/js--disable shared js
make
make-install
g++-I/home/aaditmshah/js/include/js-L/home/aaditmshah/js/lib-lmozjs185-1.0-ldl-lm-ldl-helloworld.cpp-o helloworld编译以下代码:
/*
* 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;
/* 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 = "'Hello ' + 'World!'";
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;
}
我想知道我丢失了哪些文件。我应该重建SpiderMonkey并将其安装在/usr/local
中吗?任何帮助都将不胜感激
我很确定问题不在于我使用的是静态库。我将SpiderMonkey重新构建为共享对象库,但它仍然给了我相同的错误。您可以尝试以下操作:
g++ -I/home/aaditmshah/js/include/js /home/aaditmshah/js/lib/mozjs185-1.0.a -lm -ldl helloworld.cpp -o helloworld
直接在g++命令行中添加归档文件。如果它不起作用,您可能需要指定这些的一些组合。(对于gcc 4.2,这对我来说很有效):
只需在Ubuntu 12.10、g++版本gcc 4.7.2(Ubuntu/Linaro 4.7.2-2ubuntu1)上为mozjs185-1.0.a.指定正确的路径SipderMonkey v1.8.5:命令是sudo g++-o helloworld-I/usr/local/include/js helloworld.cpp-lmozjs185-1.0-L/usr/local/lib-lpthread
花费比预期更多的时间做这么简单的事情!不感谢FireFox/Mozilla。我真的很抱歉这么说,但这对我来说很好。我得到了两个C++警告,但没有链接错误。生成的可执行文件运行良好。我在Mac电脑上。您可能希望查看nm libmozjs185-1.0.a | grep JS_NewContext
的输出。我得到一行,上面写着00000000000016d0t\u JS\u NewContext
。我得到一行,上面写着0000000000003500 T JS\u NewContext
,我假设这意味着JS\u NewContext
的值为13568
。我不知道该如何处理这个输出。不,它仍然不起作用。选项-lm
和-ldl
是什么意思?我使用的是g++versiong++-4.6.real(Ubuntu/Linaro 4.6.1-9ubuntu3)4.6.1
。
g++ -I/home/aaditmshah/js/include/js /home/aaditmshah/js/lib/mozjs185-1.0.a -lm -ldl helloworld.cpp -o helloworld
-static -lmozjs185