undefined reference when linking V8

人走茶凉 提交于 2019-12-13 05:27:51

问题


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 :/


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/15071432/undefined-reference-when-linking-v8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!