Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Issue with embedding

5 views
Skip to first unread message

Mark Lapointe

unread,
Nov 11, 2009, 4:41:27 PM11/11/09
to dev-tech-...@lists.mozilla.org
Hello,

I am trying to embed spidermonkey for the first time, and I have made
some efforts to start doing the examples from the README.html and the

Thus far the examples haven't been helpful in understanding the system
but when I go to compile I get:

[root@localhost spidertest]# gcc spider.c
/tmp/cc2UWcOn.o: In function `main':
spider.c:(.text+0x15): undefined reference to `JS_Init'
spider.c:(.text+0x2f): undefined reference to `fail'
spider.c:(.text+0x3d): undefined reference to `JS_NewContext'
spider.c:(.text+0x57): undefined reference to `fail'
collect2: ld returned 1 exit status

For:
#include "js/jsapi.h"


int main(int argc, const char *argv[])
{
#define STACK_CHUNK_SIZE 8192
/* JS variables. */
JSRuntime *rt;
JSContext *cx;
JSObject *global;

rt = JS_NewRuntime(0x400000L);
if (!rt)
fail("can't create JavaScript runtime");
cx = JS_NewContext(rt, STACK_CHUNK_SIZE);
if (!cx)
fail("can't create JavaScript context");


return 0;
}


Yes I know, not a complete example yet, but I can't help but notice
that at least 1 reference is totally deprecated according to the
documentation.

Now is there a fix? or am I just doing something blatantly wrong?

Cheers,

Mark.

Donny Viszneki

unread,
Nov 11, 2009, 4:56:02 PM11/11/09
to Mark Lapointe, dev-tech-...@lists.mozilla.org
On Wed, Nov 11, 2009 at 4:41 PM, Mark Lapointe <ma...@revynet.org> wrote:
> [root@localhost spidertest]# gcc spider.c
> /tmp/cc2UWcOn.o: In function `main':
> spider.c:(.text+0x15): undefined reference to `JS_Init'
> spider.c:(.text+0x2f): undefined reference to `fail'
> spider.c:(.text+0x3d): undefined reference to `JS_NewContext'
> spider.c:(.text+0x57): undefined reference to `fail'
> collect2: ld returned 1 exit status
>
> Now is there a fix? or am I just doing something blatantly wrong?

I don't know where fail() is supposed to have been defined (it isn't a
public Spidermonkey API, so you should probably define it yourself)
but your other problems come from the fact that you haven't asked gcc
to link to spidermonkey.

Try "gcc -lmozjs spider.c"

That is a lower-case "L," a gcc option to ask gcc to search various
directories for a library file named libmozjs.something. The
.something might be .dll (Microsoft Dynamic Link Library,) .so (Shared
Object,) .a (Archive,) or something even more exotic.

Use an upper-case "L" to tell gcc about extra places to search for
your library file:

gcc -L/path/to/my/libmozjs/library -lmozjs spider.c

It's also worth noting that you can also just specify a library
filename on the commandline like this, but it's not recommended:

gcc /path/to/my/libmozjs/library/libmozjs.so spider.c

Also with the -o option you can direct the output of gcc to a
filename, so you don't get a program with the default linker output
filename like "a.out" or "a.exe."

Happy hacking :)

--
http://codebad.com/

0 new messages