1 -- use scons to compile Code
Scons is a make tool written in Python.Program. Compared with the make tool, the scons configuration file is simpler and clearer. Scons depends on python2.x. Therefore, you must install python2.x and sojns before compiling V8.
Download scons: consumer.
Install the SDK as follows.
$ Root> Cd scons-2.2.0 $ root> Python setup. py install
After installing python2.x and scons, follow these steps to compile V8:
Step 01 download V8 through SVNSource code.
$ SVN Co SVN checkout http://v8.googlecode.com/svn/trunk/objs/V8
Step 02 use scons to compile V8 code.
$ CD/objs/V8 $ scons library = static
If everything goes smoothly, the following information will be displayed at the end of the compilation output:
Ranlib libv8preparser. ascons: done building targets. ######################################## ############### warning: building V8 with scons is deprecated and # will not work much longer. please switch to using # The gyp-based build now. instructions are at # http://code.google.com/p/v8/wiki/BuildingWithGYP. ######################################## ################
This warning indicates that scons is no longer recommended for V8 to compile code. Instead, Gyp is used to compile code. Next we will try to compile V8 using gyp.
2 -- use gyp to compile code
Step 01 download the V8 source code through SVN.
$ SVN Co SVN checkout http://v8.googlecode.com/svn/trunk/objs/V8
Step 02 start compilation.
$ Make ia32
Note the following commands to generate a static library during compilation:
AR (target)/objs/V8/out/ia32.release/obj.tar get/tools/Gyp/libpreparser_lib.aar (target) /objs/V8/out/ia32.release/obj.tar get/tools/Gyp/libv8_base.aar (target)/objs/V8/out/ia32.release/obj.tar get/tools/Gyp/destroy (target) /objs/V8/out/ia32.release/obj.tar get/tools/Gyp/libv8_snapshot.a
Here we can find the location where V8 finally generates the library.
3 -- Test V8 example
After V8 is successfully installed, you can't wait to write a small program to see the charm of V8 programming. If there is no suitable example, you can refer to the following helloworld. save CPP and makefile and test it directly.
Save the following code snippet as helloworld. cpp:
# Include <v8.h> using namespace V8; int main (INT argc, char * argv []) {// create a stack-allocated handle scope. handlescope handle_scope; // create a new context. persistent <context> context = context: New (); // enter the created context for compiling and // running the hello World script. context: Scope context_scope (context); // create a string containing the JavaScript source code. handle <string> Source = string: New ("'hello' + ', world! '"); // Compile the source code. handle <SCRIPT> script = Script: Compile (source); // run the script to get the result. handle <value> result = script-> Run (); // dispose the persistent context. context. dispose (); // convert the result to an ASCII string and print it. string: asciivalue ASCII (result); printf ("% s \ n", * ASCII); Return 0 ;}
Save the following code snippet as makefile:
V8inc: =-I/objs/V8/javasdev8lib: =/objs/V8/out/ia32.release/obj.tar get/tools/Gyp/libv8 _ {base, snapshot }. AAll: helloworldhelloworld: helloworld. CPP g ++-O helloworld. CPP $ {v8inc }$ {v8lib}-lpthread