My favorites | Sign in
Logo
v8
                
Search
for
Updated Apr 21, 2009 by sgje...@chromium.org
BuildingOnWindows  
Detailed instructions for building V8 on Windows.

Building on Windows

After having installed all the prerequisites you need to add both Python and SCons to you PATH. The following example assumes that Python version 2.5.2 and SCons version 1.0.0 have been installed in their default locations.

> set PATH=C:\Python25;C:\Python25\Scripts;%PATH%`
> scons

See below for additional information on building on different versions of Visual Studio.

There are Visual Studio project files located in tools\visual studio for building V8 using the Visual Studio IDE. Please refer to the README.txt file in that directory for details. When using the Visual Studio IDE for building the project please update the PATH in My Computer->Properties->Advanced->Environment Variables as the Visual Studio project files uses Python for some of the build steps.

Using Visual Studio 2005

SCons 1.0.0 should be able to detect Visual Studio 2005 and set up the build environment automatically so no additional options should be required to run the commands mentioned in the documentation.

To build using Visual Studio 2005 however requires Visual Studio 2005 SP1 to be installed. Please download and install VS80sp1-KB926601-X86-ENU.exe from Microsoft. Link errors like the one below is an indication of Visual Studio 2005 SP1 not beeing installed.

LIBCMTD.lib(stdexcpt.obj) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in mksnapshot.obj
LIBCMTD.lib(stdexcpt.obj) : error LNK2005: "public: virtual char const * __thiscall std::exception::what(void)const " (?what@exception@std@@UBEPBDXZ) already defined in mksnapshot.obj

Selecting Visual Studio C++ Runtime Library

The SCons build has an option to control which Visual Studio C++ Runtime Library to use when linking V8. The possible options are static (statically linked in to the V8 library) and dynamic (using the DLL version). The default is static. The following example uses the shared runtime library.

> scons msvcrt=shared

NOTE: The runtime library to use (static or shared) can be selected independently of the type selected for the V8 library itself (also static or shared).

Controlling Link-time Code generation

The SCons build option msvcltcg can be used to control whether Visual C++ is instructed to do link-time code generation or not. The default is on the it can be switched off using off.

> scons msvcltcg=off

Using Visual Studio 2008

As SCons version 1.0.0 does not detect Visual Studio 2008, you will need to supply an additional env option to SCons. The env option is used to override the environment paths SCons is using. For Visual Studio 2008 it is required to override PATH, INCLUDE and LIB. The following example passes these paths for a Visual Studio 2008 installation assuming that the default installation directories have been used.

> scons env="PATH:C:\Program Files\Microsoft Visual Studio 9.0\VC\bin;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools,INCLUDE:C:\Program Files\Microsoft Visual Studio 9.0\VC\include;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include,LIB:C:\Program Files\Microsoft Visual Studio 9.0\VC\lib;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib"

Using Visual C++ Express 2008

As for Visual Studio 2008 SCons alos does not detect Visual C++ Express 2008 and the env options to SCons is required. In contrast to Visual Studio 2008 the path for Visual C++ Express 2008 are determined correctly so only include and library paths have to be overridden. The following example passes the include and library path for a Visual C++ Express 2008 installation assuming that the default installation directories have been used.

>scons env="INCLUDE:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include;C:\Program Files\Microsoft Visual Studio 9.0\VC\include,LIB:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files\Microsoft Visual Studio 9.0\VC\lib"

Running tests on Windows

When running the tests using tools\test.py on Windows SCons is used to build the tests written in C++. Therefore if using Visual Studio 2008 or Visual C++ Express 2008 the additional ´env´ option have to be passed. The script tools\test.py has an option -S to specify options which are passed to SCons. For Visual C++ Express 2008 it will look like this.

>tools\test.py -S env="INCLUDE:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include;C:\Program Files\Microsoft Visual Studio 9.0\VC\include,LIB:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files\Microsoft Visual Studio 9.0\VC\lib"

When running tests turning off link-time code generation will reduce link time significally. This is useful when running the tests repeatedly.

>tools\test.py -S msvcltcg=off

Building the hello_world sample on Windows

To build the hello_world.cpp sample from the Getting Started section of the documentation on Windows you can use the Microsoft C++ compiler cl directly. First open either the Visual Studio 2005 Command Prompt or the Visual Studio 2008 Command Prompt depending on your version if Visual Studio. Change to the directory where V8 is checked out (and v8.lib is located). Place the file hello_world.cpp there and run:

cl /Iinclude hello_world.cpp v8.lib

This will produce hello_world.exe ready to run.

If using a shared library use the following command to compile hello_world.cpp:

cl /Iinclude /DUSING_V8_SHARED hello_world.cpp v8.lib

This will produce hello_world.exe requiring v8.dll in the current directory or on the PATH to run.


Comment by loriaCarlos, Oct 28, 2008

Yes autolysis line works fine but just be sure your SDK is being correctly pointed at (in my case was "...\Microsoft SDKs\Windows\v6.0a\Include"). Otherwise you might get src\platform-win32.cc(52) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory

Comment by AridTag, Nov 20, 2008

Just a comment there is a spelling mistake.

After having installed all the prerequisites you need to add both Python and SCons to you PATH.

Should be your PATH.

Comment by sphair, Jan 03, 2009

For those using a 64bit Os, VC is split into both "Program Files", and "Program Files (x86)". Here is a modified scons command that works with this setup:

scons env="PATH:C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools,INCLUDE:C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include;C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Include;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include,LIB;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib"

Comment by klapautius, Jan 04, 2009

Using Shared v8 in Visual Studio 2003 (VC7.1) with delayed loading

The problem for vc71 is in the default arguments to some function declarations. These are simple to remove, but you'll obviously need to supply them explicitly.

Now, I wanted to be able to NOT use scripting in my app. Linking explicitly fails with a bunch of errors. Enter delayed loading:

  • compile with preproc macro USING_V8_SHARED defined
  • link with the import library
  • enter v8.dll under Linker Input page, in section "delay loaded DLLs" (bottom)
  • Wrap the v8-VS2003 header as shown below

The only problem with delayed loading is that we get LNK1194 due to data import from the library (in release mode) This is due to optimization, so we can turn it off temporarily. For me, the following was enough:

// avoid a warning
#pragma warning( disable : 4251 )

// Allows delay-loading v8.dll
#pragma optimize("g", off)
#include "v8-VS2003.h"
#pragma optimize("", on)

You can now either just use the v8 lib functions (the module is loaded automatically on first call), or check that it exists by calling LoadLibrary?("v8.dll") and testing the returned handle before use.

Comment by mariojaun, Feb 15, 2009

Why do I get the following error while compiling the helloworld sample or the entire V8 source to a shared library?

platform-win32.obj : error LNK2001: unresolved external symbol imptimeGetTime@0 v8.dll : fatal error LNK1120: 1 unresolved externals

I'm using: - Windows Vista x86 - Visual Studio 2008 - Python 2.6.1 - SCons v1.2.0.r3842

If I try to compile the VS project, the same thing is happening: Static Library --> No Problems Shared Library --> Same Error

Thanks for help and sorry for my bad English.

Comment by paulbernuau, Feb 19, 2009

I had exactly the same problem.

I added Winmm.lib to the linker and it works.

(Hope it helps)

Comment by mariojaun, Feb 22, 2009

Hi paulbernuau! Thank you very much for your answer! Now I can build a shared library if I simply add the Winmm.lib to the VS project! But I don't know how to add the library when using SConstructor to build the V8 engine!? Would be nice if somebody could tell me how to do that. But that isn't very important. I think I can go on using VS. Thanks!

Comment by webphoenix.org, Feb 27, 2009

When I use the v8 in VC8 MFC Apps,It's show some errors like this: v8.h(424) : error C2059: syntax error : "string" v8.h(424) : error C2091: function return function and so on Who can tell me why and how to solve it? Thanks for help!

Comment by Sean.Kan...@gmail.com, Mar 26, 2009

I've got some linking errors with VS2005+windows sdk 6.1 and solved by adding 2 libs "C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib\Winmm.lib" "C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib\WSock32.lib"

Comment by grusifix, Apr 27, 2009

Linking winmm.lib and WSock32.lib should be added to the actual instruction.

Comment by plmdvy, May 04, 2009

is it possible to build v8 on mingw on windows?

Comment by benjaminmaggi, Jun 16, 2009

I whant to build V8 under gcc-cygwin enviroment, is it possible ?

Comment by dushmis, Aug 08, 2009
Comment by datta.sandeep, Sep 08, 2009

The build fails on my machine even though I have VS2005 installed on it. To fix it I had to use the following command line...

>vsvars32.bat 
>scons msvcrt=shared env="INCLUDE:%INCLUDE%,LIB:%LIB%"
Comment by n.vaughan, Oct 23, 2009

Hi,

When I build with

"scons mode=debug snapshot=on msvcrt=shared"

It fails with:

C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\typeinfo(139) : error C2220: warning treated as error - no 'obje ct' file generated C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\typeinfo(139) : warning C4275: non dll-interface class 'stdext:: exception' used as base for dll-interface class 'std::bad_cast'

C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\exception(241) : see declaration of 'stdext::exception' C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\typeinfo(138) : see declaration of 'std::bad_cast'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\typeinfo(160) : warning C4275: non dll-interface class 'stdext:: exception' used as base for dll-interface class 'std::bad_typeid'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\exception(241) : see declaration of 'stdext::exception' C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\typeinfo(159) : see declaration of 'std::bad_typeid'
scons: obj\debug\mksnapshot.obj? Error 2 scons: building terminated because of errors.

D:\Development\thirdparty\v8>

Any ideas?

Comment by kurt.griffiths, Nov 12, 2009

To get the hello world sample to build, I also had to add ws2_32.lib. So here's my complete command line:

cl /Iinclude v8.lib Winmm.lib WSock32.lib hello_world.cpp ws2_32.lib

Comment by iamyuguo, Nov 27, 2009

When I use MinGW with toolchain=gcc set, it generates commands like this:

cl /Foobj\release\dtoa-config.obj /c src\dtoa-config.c -Werror -Wno-uninitialize d -m32 -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -DWIN32 /DV8 TARGET_ARCH_IA32 /DENABLE_DEBUGGER_SUPPORT /DV8_NATIVE_REGEXP /DENABLE_LOGGING AND_PROFILING /Isrc

Why? And how am I to compile it using MinGW?

Comment by bolter.fire, Dec 18, 2009

Anyone to put statically linked version somewhere? I cant build it too.

Comment by toyotabedsrock, Dec 18, 2009

Has anyone tried to used the Intel 11.x compiler?


Sign in to add a comment