源碼安裝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](
https://stackoverflow.com/questions/24279237/android-ndk-linking-v8-static-library-cannot-find-symbols-but-they-are-there)。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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章