v8 你好世界示例链接错误

v8 hello world example link error

本文关键字:链接 错误 你好 世界 v8      更新时间:2023-10-16

我阅读了 V8 hello world 示例,并按照文档中的步骤成功构建了 v8。

但是当我编译示例代码时,发生了链接错误。这是我的计算机详细信息和错误提示。

  1. 操作系统 Ubuntu 13.10 amd64
  2. GCC (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
  3. 编译命令:
g++ -Iinclude hello_world.cc -o hello_world -Wl,--start-group out/native/obj.target/{tools/gyp/libv8_{base.x64,snapshot},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt

错误提示

/usr/bin/ld: /home/leon/Documents/v8/v8/out/native/obj.target/v8_base.x64/src/platform/mutex.o: undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

该错误表明您需要将pthread库添加到链接命令中。只需附加-lpthread.

(有点奇怪的是,它准确地确定了你需要哪个库,然后告诉你它拒绝使用它,因为你没有在命令行上列出它......