链接V8时未定义的引用

undefined reference when linking V8

本文关键字:引用 未定义 V8 链接      更新时间:2023-10-16

我正在努力用V8.编译一个非常小的例子

cpp程序是这样的:

#include "v8.h"
int main()
{
     v8::HandleScope handle_scope;
     return 0;
}

编译行:g++-I/home/alterje/git/tengine/Externals/v8/include/home/alternje/git/tengine/Eexternals/v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.atest.cpp-o test-lpthread

我得到的错误:

/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

基本、快照和无快照库文件之间究竟有什么区别?我尝试过与它们中的每一个链接,但都不起作用:/

首先我得为我糟糕的英语说声抱歉。我刚刚把.a文件链接到我自己的项目。由于未给定libv8_snapshot.a的依赖项,因此出现ld错误。

这是我的编译声明:

g++-o xxxxx-I~v8/out/nature/obj.target/tools/gyp/libv8_{base.nature,snapshot}.a~v8/out/nature/obj.target_third_party/icu/libicu{data,i18n,snapshot}.a~v8/1out/naturt/obj.ttarget/icudata/third_paarty/icu/linux/icudt46_dat.o-lrt-lpthread

我认为libv8_base.natur.a libv8_snapshot.a依赖于icu和icudt46文件,并且unix clock_time的一些函数依赖于"rt",所以添加"-lrt">

希望对大家有所帮助~作为一个中国人,对不起我的英语。

编译行:
g++-I/home/alterje/git/tengine/Externals/v8/include/home/alternje/git/tengine/Eexternals/v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.atest.cpp-o test-lpthread

此链接线不正确。试试这个:

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

阅读此内容,了解订单为何重要。