bitgregor
bitgregor

Reputation: 1125

undefined reference when linking V8

I'm strugling to compile a really small example with V8..

cpp program is this:

#include "v8.h"

int main()
{
     v8::HandleScope handle_scope;

     return 0;
}

Compile line: g++ -I/home/lterje/git/tengine/Externals/v8/include /home/lterje/git/tengine/Externals/v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.a test.cpp -o test -lpthread

Error I'm getting:

/tmp/ccHYtJuE.o: In function `main':
test.cpp:(.text+0x11): undefined reference to `v8::HandleScope::HandleScope()'
test.cpp:(.text+0x22): undefined reference to `v8::HandleScope::~HandleScope()'
collect2: error: ld returned 1 exit status

What exactly is the difference between the base, snapshot and no snapshot library files? I've tried linking with each of them, but none of them works :/

Upvotes: 0

Views: 2973

Answers (2)

ChenClock
ChenClock

Reputation: 21

first I have to say sorry for my poor english. I have just link the .a file to my own project. There's ld error because of the dependencies of the libv8_snapshot.a is not been given.

This is my compile statement:

g++ -o xxxxx -I ~v8/out/native/obj.target/tools/gyp/libv8_{base.native,snapshot}.a ~v8/out/native/obj.target/third_party/icu/libicu{data,i18n,snapshot}.a ~v8/out/native/obj.target/icudata/third_party/icu/linux/icudt46_dat.o -lrt -lpthread

I think that the libv8_base.native.a libv8_snapshot.a is dependend on icu and icudt46 files and thereis some functions about unix clock_time is dependend on "rt", so add "-lrt"

Hope helpful for you all~ As a Chinese,sorry for my english.

Upvotes: 2

Employed Russian
Employed Russian

Reputation: 213799

Compile line:
g++ -I/home/lterje/git/tengine/Externals/v8/include /home/lterje/git/tengine/Externals/v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.a test.cpp -o test -lpthread

This link line is incorrect. Try this instead:

g++ -I/home/lterje/git/tengine/Externals/v8/include \
  test.cpp -o test \
  /home/.../obj.target/tools/gyp/libv8_snapshot.a \
  -lpthread

Read this to understand why the order matters.

Upvotes: 0

Related Questions