源码安装v8报错

想试试v8嵌入到c++开发
网上写编译v8的文章不多,且我觉得大部分写得不够详细。
官方Building from Source已提供安装步骤,本文没必要对里面的大部分内容再费唇舌
下文记录编译&安装v8所遇到的问题,希望能帮到大家。

v8版本:v8 6.9

系统环境:

[amao@localhost x64.release]$ lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:    CentOS
Description:    CentOS release 6.9 (Final)
Release:    6.9
Codename:    Final,

depot_tools&v8下载失败?

官方建议使用depot_tools来下载v8,而不是简单地从github仓库git clone。然而v8和depot_tools都存放再googlesource,在国内访问不到。

[amao@iZwz9a2i9usy5z9rlul2voZ dsfdf]$ fetch v8
Running: gclient root
depot_tools update failed. Conflict in /home/amao/depot_tools
Cannot rebase: You have unstaged changes.
Please commit or stash them.
curl: (7) Failed connect to chrome-infra-packages.appspot.com:443; Connection timed out
/home/amao/.gclient_entries missing, .gclient file in parent directory /home/amao might not be the file you want to use.
Running: gclient config --spec 'solutions = [
 {
   "url": "https://chromium.googlesource.com/v8/v8.git",
   "managed": False,
   "name": "v8",
   "deps_file": "DEPS",
   "custom_deps": {},
 },
]
'
depot_tools update failed. Conflict in /home/amao/depot_tools
Cannot rebase: You have unstaged changes.
Please commit or stash them.
Bootstrapping cipd client for linux-amd64 from https://chrome-infra-packages.appspot.com/client?platform=linux-amd64&version=git_revision:4d19637ec2c3d1efd8c6a1b05285118b786919e2...
curl: (7) Failed connect to chrome-infra-packages.appspot.com:443; Connection timed out
Running: gclient sync --with_branch_heads

这里分享我下载好的depot_tool&v8
depot_tools:https://pan.baidu.com/s/10lWOMwv0BuKi2R5hlVcI9g
v8 6.9源码:https://pan.baidu.com/s/1wHmOynP6YfLmfm7tMkIUig

如何配置depot_tools

Building from Source只给了配置depot_tools的跳转连接。不幸的是,页面在国内访问失败。以下截图是链接里官网提供的配置步骤

python&gcc版本。

Building from Source并没有提及各个v8版本,要求的最低python和gcc版本, 这导致ninja -C out.gn/x64.release命令,大部分情况下编译失败。这花费了我大部分时间,非常苦恼!

最终在pythong 2.7.9和gcc 5.5.0的版本下,成功编译v8 6.9

编译成功,可是比较官方文档,发现有些静态库没有生成,如libv8_base.a

tools/dev/v8gen.py x64.release命令创建编译选项配置,默认只会生成libv8_libbase.a和libv8_libplatfrom.a这两个静态库。如果你想将v8嵌入到c++,建议参考官方Embedding V8,按照说明修改编译选项,重编译即可。
可以参考我的hello-world工程https://pan.baidu.com/s/1ztJO4PUmeICLVBoUt5ljrg

静态库路径都正确,链接报错”could not read symbols: No such file or directory”

编译&输出的静态库是thin format library,它只包含定义的引用,没有符号&定义内容,参考stackoverflow。v8这样做是为了降低应用包体大小,和便于patch更新。这篇文章介绍将v8符号&定义内容打进一个包的方法
所以需要将这些thin format library所引用的文件,同时拷贝一份到你的工程。

In fact, the “.a” files of the default build is not actually ar static library, it’s “thin archive” format which contains reference to other object files instread of packing object files together in one file. That’s to say, if you copy only the .a files to other people, they will not be able to compile because the referenced object files are missing.


可以比较一下系统路径下的/usr/bin/librpcsvc.a



原文:
https://lizijie.github.io/2018/07/03/%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85v8%E6%8A%A5%E9%94%99.html
作者github:
https://github.com/lizijie

PREVIOUSRaknet研究
NEXTlibevent 偏移读取缓存evbuffer_copyout_from