google V8 javascript引擎编译测试

本文记录了在Cygwin环境下编译V8 JavaScript引擎的过程,包括下载源码、依赖项配置及遇到的编译错误和解决方法。通过修改平台相关代码,最终成功编译并生成了库文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上次编译了Gumbo,接着来看看V8 JavaScript引擎吧,下载了v8-trunk

复制到f:/pbase/v8-trunk

接下来在cygwin下编译

cd /cygdrive/f/pbase/v8-trunk

然后执行命令

make dependencies

会陆续下载一系列的包和编译所以来的内容

A    third_party/icu/patches/uloc.patch
A    third_party/icu/patches/data.build.win.patch
A    third_party/icu/patches/ios_timezone.patch
A    third_party/icu/patches/wpo.patch
A    third_party/icu/patches/gcc46.patch
A    third_party/icu/patches/pmac.h.patch
A    third_party/icu/patches/vscomp.patch
A    third_party/icu/patches/data.build.patch
Checked out revision 214189.

在cygwin下,输入如下命令

签出cygwin:

 

签出python:

签出gyp:
svn co  http://gyp.googlecode.com/svn/trunk build/gyp 

 

然后执行编译

huareal@gpx /cygdrive/f/pbase/v8-trunk
# make ia32.release.check
PYTHONPATH="/cygdrive/f/pbase/v8-trunk/tools/generate_shim_headers:" \
        GYP_GENERATORS=make \
        build/gyp/gyp --generator-output="out" build/all.gyp \
                      -Ibuild/standalone.gypi --depth=. \
                      -Dv8_target_arch=ia32 \
                      -S.ia32  -Dv8_enable_backtrace=1 -Darm_fpu=default -Darm_float_abi=default
cygwin warning:
  MS-DOS style path detected: C:\Users\huareal/.gyp
  Preferred POSIX equivalent is: /cygdrive/c/Users/huareal/.gyp
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
make[1]: Entering directory `/cygdrive/f/pbase/v8-trunk/out'
  ACTION tools_gyp_v8_gyp_js2c_target_js2c /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj/gen/libraries.cc
  CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/accessors.o
开始编译了

编译过程是比较慢,可以喝点茶,等一等

会输出很多类似的编译记录

 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/mark-compact.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/marking-thread.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/messages.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/objects-debug.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/objects-printer.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/objects-visiting.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/objects.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/once.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/optimizing-compiler-thread.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/parser.o
 CXX(target) /cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/preparse-data.o

编译结果出现错误

../src/platform-posix.cc: In static member function ‘static void v8::internal::OS::ProtectCode(void*, size_t)’:
../src/platform-posix.cc:139: error: ‘DWORD’ was not declared in this scope
../src/platform-posix.cc:139: error: expected `;' before ‘old_protect’
../src/platform-posix.cc:140: error: ‘PAGE_EXECUTE_READ’ was not declared in this scope
../src/platform-posix.cc:140: error: ‘old_protect’ was not declared in this scope
../src/platform-posix.cc:140: error: ‘VirtualProtect’ was not declared in this scope
../src/platform-posix.cc: In static member function ‘static void v8::internal::OS::Guard(void*, size_t)’:
../src/platform-posix.cc:154: error: ‘DWORD’ was not declared in this scope
../src/platform-posix.cc:154: error: expected `;' before ‘oldprotect’
../src/platform-posix.cc:155: error: ‘PAGE_READONLY’ was not declared in this scope
../src/platform-posix.cc:155: error: ‘PAGE_GUARD’ was not declared in this scope
../src/platform-posix.cc:155: error: ‘oldprotect’ was not declared in this scope
../src/platform-posix.cc:155: error: ‘VirtualProtect’ was not declared in this scope
make[1]: *** [/cygdrive/f/pbase/v8-trunk/out/ia32.release/obj.target/v8_base.ia32/src/platform-posix.o] Error 1
make[1]: Leaving directory `/cygdrive/f/pbase/v8-trunk/out'
make: *** [ia32.release] Error 2

 

尝试用如下命令编译

make native mode=debug library=shared snapshot=on  

依然有上述错误,看了platform-posix.cc的文件存在错误

修改代码:platform-posix.cc的行139,154对应的代码,屏蔽DWORD的引用,保留mprotect(address, size, PROT_READ | PROT_EXEC);和

mprotect(address, size, PROT_NONE);

代码如下

// Get rid of writable permission on code allocations.
void OS::ProtectCode(void* address, const size_t size) {
//#if defined(__CYGWIN__)
//  DWORD old_protect;
//  VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
//#elif defined(__native_client__)
  // The Native Client port of V8 uses an interpreter, so
  // code pages don't need PROT_EXEC.
//  mprotect(address, size, PROT_READ);
//#else
  mprotect(address, size, PROT_READ | PROT_EXEC);
//#endif
}


// Create guard pages.
void OS::Guard(void* address, const size_t size) {
//#if defined(__CYGWIN__)
//  DWORD oldprotect;
//  VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect);
//#else
  mprotect(address, size, PROT_NONE);
//#endif
}

 

继续编译

  CXX(target) /cygdrive/f/pbase/v8-trunk/out/native/obj.target/preparser/preparser/preparser-process.o
  CXX(target) /cygdrive/f/pbase/v8-trunk/out/native/obj.target/preparser/src/preparser-api.o
  LINK(target) /cygdrive/f/pbase/v8-trunk/out/native/preparser
  CXX(target) /cygdrive/f/pbase/v8-trunk/out/native/obj.target/v8/src/v8dll-main.o
  SOLINK(target) /cygdrive/f/pbase/v8-trunk/out/native/obj.target/tools/gyp/libv8.so
  COPY /cygdrive/f/pbase/v8-trunk/out/native/lib.target/libv8.so
  CXX(target) /cygdrive/f/pbase/v8-trunk/out/native/obj.target/shell/samples/shell.o
  LINK(target) /cygdrive/f/pbase/v8-trunk/out/native/shell
  CXX(target) /cygdrive/f/pbase/v8-trunk/out/native/obj.target/process/samples/process.o
  LINK(target) /cygdrive/f/pbase/v8-trunk/out/native/process
  CXX(target) /cygdrive/f/pbase/v8-trunk/out/native/obj.target/lineprocessor/samples/lineprocessor.o

貌似已经编译成功,接下来继续编译tes的内容

  LINK(target) /cygdrive/f/pbase/v8-trunk/out/native/cctest
  TOUCH /cygdrive/f/pbase/v8-trunk/out/native/obj.target/build/All.stamp
make[1]: Leaving directory `/cygdrive/f/pbase/v8-trunk/out'

编译完毕,

手动把

F:\pbase\v8-trunk\out\native\lib.target\libv8.so复制到/usr/lib下即可

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值