This document introduces some key V8 concepts and provides a
hello world example to get you started with V8 code.
First, some key concepts you will need:
These concepts are discussed in greater detail in the [[Embedder‘s Guide|Embedder’s Guide]].
Follow the steps below to run the example yourself:
Download the V8 source code by following the [[git|Using-Git]] instructions.
The instructions for this hello world example has last been tested with V8 7.1.11. You can check out this branch with
git checkout refs/tags/7.1.11 -b sample -t
Create a build configuration using the helper script:
tools/dev/v8gen.py x64.release.sample. You can inspect and manually edit the build configuration by running
gn args out.gn/x64.release.sample.
ninja -C out.gn/x64.release,sample v8_monolith on a Linux x64 system to generate the correct binaries.
hello-world.cc, linking to the static libraries created in the build process. For example, on 64bit Linux using the GNU compiler:
g++ -I. -Iinclude samples/hello-world.cc -o hello_world -lv8_monolith -Lout.gn/x64.release.sample/obj/ -pthread -std=c++0x
For more complex code, V8 will fail without an ICU data file. Copy this file to where your binary is stored:
cp out.gn/x64.release.sample/icudtl.dat .
hello_world executable file at the command line. e.g. On Linux, in the V8 directory, run:
You will see
Of course this is a very simple example and it‘s likely you’ll want to do more than just execute scripts as strings! For more information see the [[Embedder‘s Guide|Embedder’s Guide]]. If you are looking for an example which is in sync with master simply check out the file