compiling an embedded spidermonkey javascript engine in C++ application gives me errors, however I followed the steps in the documentation

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

compiling an embedded spidermonkey javascript engine in C++ application gives me errors, however I followed the steps in the documentation

Sara
I downloaded the SpiderMonkey source code using version 1.8.5 Then I successfully built the include files and static library by executing the following commands:

autoconf2.13
./configure
make
make install

Now I tried compiling the following code using the command g++
////////////////////////////////////////////////////////////////////////
 /* 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.
     */
    const 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 == 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;
}
/////////////////////////////////////////////////////
The command that I used

     " g++ -Ihome/SpiderMonkey/js-1.8.5/js/src/dist/include
     -Lhome/SpiderMonkey/js1.8.5/js/src/dist/bin -lmozjs185  helloworld.cpp -o "


the error is :

In function `main':
helloworld.cpp:(.text+0x6e): undefined reference to `JS_Init'
helloworld.cpp:(.text+0x94): undefined reference to `JS_NewContext'
helloworld.cpp:(.text+0xba): undefined reference to `JS_SetOptions'
helloworld.cpp:(.text+0xcb): undefined reference to `JS_SetVersion'
helloworld.cpp:(.text+0xdc): undefined reference to `JS_SetErrorReporter'
helloworld.cpp:(.text+0xf2): undefined reference to `JS_NewCompartmentAndGlobalObject'
helloworld.cpp:(.text+0x11a): undefined reference to `JS_InitStandardClasses'
helloworld.cpp:(.text+0x191): undefined reference to `JS_EvaluateScript'
helloworld.cpp:(.text+0x1c8): undefined reference to `JS_ValueToString'
helloworld.cpp:(.text+0x1df): undefined reference to `JS_EncodeString'
helloworld.cpp:(.text+0x1f3): undefined reference to `JS_DestroyContext'
helloworld.cpp:(.text+0x1ff): undefined reference to `JS_Finish'
helloworld.cpp:(.text+0x204): undefined reference to `JS_ShutDown'
/tmp/ccUU9may.o:(.data+0x10): undefined reference to `JS_PropertyStub'
/tmp/ccUU9may.o:(.data+0x18): undefined reference to `JS_PropertyStub'
/tmp/ccUU9may.o:(.data+0x20): undefined reference to `JS_PropertyStub'
/tmp/ccUU9may.o:(.data+0x28): undefined reference to `JS_StrictPropertyStub'
/tmp/ccUU9may.o:(.data+0x30): undefined reference to `JS_EnumerateStub'
/tmp/ccUU9may.o:(.data+0x38): undefined reference to `JS_ResolveStub'
/tmp/ccUU9may.o:(.data+0x40): undefined reference to `JS_ConvertStub'
/tmp/ccUU9may.o:(.data+0x48): undefined reference to `JS_FinalizeStub'
 collect2: ld returned 1 exit status  
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: compiling an embedded spidermonkey javascript engine in C++ application gives me errors, however I followed the steps in the documentation

Anthony Catel-4
You forgot to link against the lib or gave a wrong L path.

A.

> On 02.12.2013, at 18:47, Sara <[hidden email]> wrote:
>
> I downloaded the SpiderMonkey source code using version 1.8.5 Then I successfully built the include files and static library by executing the following commands:
>
> autoconf2.13
> ./configure
> make
> make install
>
> Now I tried compiling the following code using the command g++
> ////////////////////////////////////////////////////////////////////////
> /* 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.
>     */
>    const 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 == 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;
> }
> /////////////////////////////////////////////////////
> The command that I used
>
>     " g++ -Ihome/SpiderMonkey/js-1.8.5/js/src/dist/include
>     -Lhome/SpiderMonkey/js1.8.5/js/src/dist/bin -lmozjs185  helloworld.cpp -o "
>
>
> the error is :
>
> In function `main':
> helloworld.cpp:(.text+0x6e): undefined reference to `JS_Init'
> helloworld.cpp:(.text+0x94): undefined reference to `JS_NewContext'
> helloworld.cpp:(.text+0xba): undefined reference to `JS_SetOptions'
> helloworld.cpp:(.text+0xcb): undefined reference to `JS_SetVersion'
> helloworld.cpp:(.text+0xdc): undefined reference to `JS_SetErrorReporter'
> helloworld.cpp:(.text+0xf2): undefined reference to `JS_NewCompartmentAndGlobalObject'
> helloworld.cpp:(.text+0x11a): undefined reference to `JS_InitStandardClasses'
> helloworld.cpp:(.text+0x191): undefined reference to `JS_EvaluateScript'
> helloworld.cpp:(.text+0x1c8): undefined reference to `JS_ValueToString'
> helloworld.cpp:(.text+0x1df): undefined reference to `JS_EncodeString'
> helloworld.cpp:(.text+0x1f3): undefined reference to `JS_DestroyContext'
> helloworld.cpp:(.text+0x1ff): undefined reference to `JS_Finish'
> helloworld.cpp:(.text+0x204): undefined reference to `JS_ShutDown'
> /tmp/ccUU9may.o:(.data+0x10): undefined reference to `JS_PropertyStub'
> /tmp/ccUU9may.o:(.data+0x18): undefined reference to `JS_PropertyStub'
> /tmp/ccUU9may.o:(.data+0x20): undefined reference to `JS_PropertyStub'
> /tmp/ccUU9may.o:(.data+0x28): undefined reference to `JS_StrictPropertyStub'
> /tmp/ccUU9may.o:(.data+0x30): undefined reference to `JS_EnumerateStub'
> /tmp/ccUU9may.o:(.data+0x38): undefined reference to `JS_ResolveStub'
> /tmp/ccUU9may.o:(.data+0x40): undefined reference to `JS_ConvertStub'
> /tmp/ccUU9may.o:(.data+0x48): undefined reference to `JS_FinalizeStub'
> collect2: ld returned 1 exit status  
> _______________________________________________
> dev-tech-js-engine mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: compiling an embedded spidermonkey javascript engine in C++ application gives me errors, however I followed the steps in the documentation

Sara
In reply to this post by Sara
On Monday, December 2, 2013 7:58:30 PM UTC+2, Anthony Catel wrote:
> You forgot to link against the lib or gave a wrong L path.
>
>
>
> A.
>
>
> g++ -Ihome/SpiderMonkey/js-1.8.5/js/src/dist/include
     -Lhome/SpiderMonkey/js1.8.5/js/src/dist/bin -lmozjs185  helloworld.cpp -o
I don't totally aware of g++ command, could you tell -I and -L what are they mean and if I should link also the lib how it should be in the command?
I followed this article https://developer.mozilla.org/en-US/docs/How_to_embed_the_JavaScript_engine  .
could you give me an example of how you compile it?
really, thank you very much
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: compiling an embedded spidermonkey javascript engine in C++ application gives me errors, however I followed the steps in the documentation

Sara
In reply to this post by Sara
On Monday, December 2, 2013 7:58:30 PM UTC+2, Anthony Catel wrote:
> You forgot to link against the lib or gave a wrong L path.
>
>
>
> A.
>
>
> g++ -Ihome/SpiderMonkey/js-1.8.5/js/src/dist/include
     -Lhome/SpiderMonkey/js1.8.5/js/src/dist/bin -lmozjs185  helloworld.cpp -o
really, thank you very much
I don't totally aware of g++ command, could you tell me what do -I and -L indicate in the command and if I should link also the lib how it should be in the command?
I followed this article https://developer.mozilla.org/en-US/docs/How_to_embed_the_JavaScript_engine  .
could you give me an example of how you compile it?
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: compiling an embedded spidermonkey javascript engine in C++ application gives me errors, however I followed the steps in the documentation

Terrence Cole-3
On 12/02/2013 10:37 AM, Sara wrote:

> On Monday, December 2, 2013 7:58:30 PM UTC+2, Anthony Catel wrote:
>> You forgot to link against the lib or gave a wrong L path.
>>
>> A.
>>
>>
>> g++ -Ihome/SpiderMonkey/js-1.8.5/js/src/dist/include
>      -Lhome/SpiderMonkey/js1.8.5/js/src/dist/bin -lmozjs185  helloworld.cpp -o
> really, thank you very much
> I don't totally aware of g++ command, could you tell me what do -I and -L indicate in the command and if I should link also the lib how it should be in the command?
> I followed this article https://developer.mozilla.org/en-US/docs/How_to_embed_the_JavaScript_engine  .
> could you give me an example of how you compile it?

That question isn't really in this list's purview. Perhaps you would be
better served consulting gcc's fine manual?

http://gcc.gnu.org/onlinedocs/

> _______________________________________________
> dev-tech-js-engine mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>

_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: compiling an embedded spidermonkey javascript engine in C++ application gives me errors, however I followed the steps in the documentation

Sara
In reply to this post by Sara
I read and understood every g++ commands, and tried different changes and solutions but with the same error?
could any one help me, please?
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine