Compiling v8 and Hello, World Example on Mac OSX Mavericks (10.9.4)
by Keith Rosenberg (netpoetica)
Note: do this in some sort of project/ directory that makes sense. depot_tools are going to need to be in your path, so you may want to install them somewhere you are comfortable with.
1) Get the v8 source
git clone https://github.com/v8/v8.git
2) Install depot tools
Note: you can read about depot_tools here
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
additionally, the path to depot tools must be available in your PATH, so add it to your ~/.zshrc or ~/.bashrc file
cd depot_tools pwd // should print ~/Desktop/git/depot_tools or the like vim ~/.zshrc // or .bashrc // Add it to the path or add this line at the bottom of your file export PATH=~/Desktop/git/depot_tools:"$PATH"
3) Add gyp and c/c++/linking configuration to your environment
First make sure clang and clang++ are in in your PATH by running
which clang && which clang++
If for some reason you do not have clang available, make sure you have the most recent Xcode command line tools installed.
and add the following:
export CXX="`which clang++`" export CC="`which clang`" export CPP="`which clang` -E" export LINK="`which clang++`" export CXX_host="`which clang++`" export CC_host="`which clang`" export CPP_host="`which clang` -E" export LINK_host="`which clang++`" export GYP_DEFINES="clang=1"
4) Install node gyp
In the command line, in the v8 folder, run
it's worth noting that some documentation says to run
from what I can tell, they both install gyp, but
make dependencies installs some third party tools you may eventually need. So either one should work, but go ahead and run both if you want (I did) - it won't hurt anything.
5) Finally, run make to create static libs for linking
Now the juicy part. In the v8 folder, you'll have to run make. v8's make lets you specify your architecture and number of cores.
However, your best bet is to let make figure out which architecture to build for your machine. If you know how many cores you have for your CPU, there is a command you can use to specify that.
If you open Activity Monitor, and then navigate to Window -> CPU Usage, the visual will pop up that looks like a bar graph. However many bars there are, that is how many cores you have.
On my machine, I have four, so I would run
make native -j 4
However, if you are unsure, just run
This may take a while (on a kind-of-crap MacBook Pro, takes about 10 minutes).
6) Now, copy the hello world example below into a new file in the v8 folder (direct child of v8 folder) and save it as hello_world.cpp
7) Finally, you're ready to compile and see hello_world.cpp's output!
In terminal,in the v8/ folder, run
clang++ -Iinclude out/native/libv8_base.a out/native/libv8_libbase.a out/native/libv8_snapshot.a out/native/libicudata.a out/native/libicuuc.a out/native/libicui18n.a hello_world.cpp -o hello_world
viola! You're now ready to start messing with v8!