【问题标题】:Linker error when compiling a program that uses spidermonkey编译使用 spidermonkey 的程序时出现链接器错误
【发布时间】:2013-12-31 08:00:00
【问题描述】:

我一直在尝试学习 spidermonkey,因此编写了以下代码,改编自 this guide,当程序正确编译时,在链接过程中出现以下错误:

/usr/bin/ld: cannot open linker script file symverscript: No such file or directory

我使用的是 64 位 Ubuntu 13.10,这里是代码(似乎与问题无关,但不会受到伤害)

#include <jsapi.h>
#include <iostream>
#include <string>

int main()
{
    std::string script = "var x = 10;x*x;";
    jsval rval;
    JSRuntime* runtime = 0;
    JSContext* context = 0;
    JSObject* globalob = 0;
    if((!(runtime = JS_NewRuntime(1024L*1024L, JS_NO_HELPER_THREADS)))||
        (!(context = JS_NewContext(runtime, 8192)))||
        (!(globalob  = JS_NewObject(context, NULL, NULL, NULL))))
    {
        return 1;
    }
    if(!JS_InitStandardClasses(context, globalob))
    {
        return 1;
    }
    if(!JS_EvaluateScript(context,globalob,script.data(),script.length(),"script",1,&rval))
    {
        return 1;
    }
    std::cout << JSVAL_TO_INT(rval) << "\n";
    JS_DestroyContext(context);
    JS_DestroyRuntime(runtime);
    JS_ShutDown();
    return 0;
}

用命令编译

g++ main.cpp -o out $(js24-config --cflags --libs | tr "\n" " ")

【问题讨论】:

    标签: c++ linker spidermonkey


    【解决方案1】:

    试着改写这个命令, g++ main.cpp -o main -I/usr/local/include/js/ -L/usr/local/lib/ -lmozjs1.8.5

    关于我上面写的路径,你必须写你自己的路径,其中包含库和 JSAPI.h 文件, 最后一个是spidermonkey库,你会在lib文件夹中找到它,对我来说它存在于/usr/local/lib中

    【讨论】:

    • 这行得通,但值得注意的是,我必须使用 /usr/include/mozjs-24 作为包含目录,以供将来可能偶然发现该问题的其他人使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 2014-10-25
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    相关资源
    最近更新 更多