Compiling Webkit on Win32

Compiling WebKit on Windows is far from trivial. In the process of getting it compiled and linked successfully, I took some notes which may help others struggling to getting it done.

First, a few precautions, don’t try to be smart. Follow the instructions on the site closely, this means:
  • Don’t try to compile w/ Visual C++ 2008, it won’t work. Use VC++ 2005.
  • For VC++ 2005 Express Ed., make sure you have SP1, compilation will fail w/o it.
  • For Vista, make sure you have the additional SP update.
  • Don’t try to compile outside of cygwin directory structure.
Next, you need to get the webkit source.
  • Get the source from a nightly build (make sure to download the source and not one of the platform specific builds). You can also get the files from the subversion repository, but I had issues with this and discovered missing files. It may have been fixed, but in general, I think just getting the nightly build is simpler.
  • The source is in a .bz2 file. So you’ll need a bzip2 decompressor.
  • The bz2 file decompresses to a .tar file (wtf?!), so you’ll also need a tar decompressor.
  • Next, download the WebKit Support Libraries.
  • Put the source under your cygwin/home/<username> directory (e.g. \cygwin\home\<username>\WebKit)
  • Finally, update, by running the update-webkit script.
Preparing for compilation.

Note: I tried to build from the cygwin shell, as demonstrated on webkit.org, but it failed. Failing in this way and then having to dig thru build logs is insane, so I diverted to building from within VC++ so I could easily spot and fix errors as they occurred.

Note: I failed to realize that I didn’t have SP1 for VC++ 2005 Express when I started this whole process and didn’t figure it out until I hit a few perplexing errors related to the linker failing because it detected different versions of the compiler were used for the 2 parts of compilation on a few object files (yea, it’s weird, I have no clue what was going on internally here). I found a few quick and dirty solutions to this problem by playing around with optimization settings, but eventually hit a brick wall, where no amount of fidgeting with optimization parameters resulted in compilation/linking going forward. Installing SP1 solved the issue and may have solved the earlier issues as well without me having to play with optimization settings.

So, onwards we go,
  • I found that after opening the WebKit solution, none of the projects were loaded. This is because the project files are looking for *.vsprops files in WebKit\WebKitLibraries\tools\vsprops, but the vsprops files are actually in WebKit\WebKitLibraries\win\tools\vsprops. The simplest solution is just copy over what’s in the /win directory into the parent directory (WebKit\WebKitLibraries). Looking at WebKit\WebKitLibraries now, I copied over the win/tools folder and the files in /win. Alternatively, you can edit the project files (they’re XML files, you can open them up in a text editor).
  • Set the 2 environment variables necessary for compiling within VC++,
    • WEBKITLIBRARIESDIR = cygwin\home\<user>\WebKit\WebKitLibraries
    • WEBKITOUTPUTDIR = cygwin\home\<user>\WebKit\WebKitBuild
  • Get the Platform SDK, specifically the Windows Server 2003 Ed. of the Platform SDK. I did not have luck getting it to work with an older or newer version of the SDK. I didn’t install the R2 update; I’m not sure what effect it would have.
  • Update VC++ directories:
    • Executables >> add cygwin/bin, windows/system32, Platform SDK/bin
    • Includes >> Platform SDK/include
    • Library Files >> Platform SDK/lib
  • Update VC++ directories for the WebKit Support Library:
    • Includes >> WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include
    • Library Files >> WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\lib
  • Update VC++ directories for JavaScriptCore/icu:
    • Includes >> WebKit\JavaScriptCore\icu
  • Update VC++ directories for WebCoreSQLite3:
    • Includes >> WebKit\WebKitLibraries\WebCoreSQLite3
  • Update VC++ directories for JavaScriptCore:
    • Includes >> WebKit\JavaScriptCore
  • I had issues with the ARRAYSIZE macro not being defined, so in WebCore/config.h, add the following:

    #ifndef ARRAYSIZE
    #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
    #endif

    right before the line,

    #endif /* PLATFORM(WIN_OS) */

  • Get rid of cygwin’s link.exe in cygwin/bin (rename it or delete it). This causes a conflict with the real linker (VC++’s link.exe). It was likely caused by the order in which VC++ executable directories were set, so if you need it, you might be able to keep it.
  • For the QtMovieWin project, edit all source files (there’s only 2) so that windows.h is included first (this is due to macro above, which will now cause a macro redefinition by the preprocessor).
  • For QtMovieWin, also rearrange the order of include, so that #include <wtf/Vector.h> is included before config.h and windows.h to prevent some min/max macro nonsense.
  • For QtMovieWin, take off prompt error reporting for linking (ERRORREPORT:PROMPT) project (see Linker >> Advanced page in project setting).
  • Make a new config file by copying WebCore/config.h and making WebCore/config_qt.h. Remove the ARRAYSIZE macro defintions from config_qt.h. Update all files in QtMovieWin project so that config_qt.h is included instead of config.h.
  • Install the QuickTime SDK.
  • Update VC++ directories:
    • Includes >> QuickTime 7.3 SDK\CIncludes
    • Library Files >> QuickTime 7.3 SDK\Libraries
  • For QtMovieWin, make sure you linker inputs are set correctly for QuickTime libraries and VC++ can find them.
  • For QtMovieWin, add “CoreFoundation.lib” to linker inputs.
  • (This may have been an issue caused by not having SP1, you might not have to do this, try compiling first) Turn off whole program optimization for all projects.
  • (This may have been an issue caused by not having SP1, you might not have to do this, try compiling first) Turn off treat warnings as errors for JavaScriptCore, WebKit, WebKitGUID, WebCore, and WTF projects.
That should do it.

Some general advice, work from within VC++ and compile as you make changes; make it a touch-and-go operation. In this way you see errors as they occur and can more easily spot and fix issues. Don’t simply follow what I’ve written above as tutorial thinking it’s a sure-fire solution for compilation, things may very likely change with different iterations of the code.

15 Comments

  1. Anonymous

    Hi Avishkar …. I have been following ur post on how to set up webkit on windows… Have done all the required steps .. but when i compile the webkit .. i get some fatal errors… like cannot find unicode/pwin32.h … if possible can u guide me as to how can i solve this error and move ahead with my development…. thanks a lot in advance.
    –Debug

  2. Avishkar Autar

    I think I forgot an important include directory,

    Update your VC++ directories and add the following directory:
    “WebKit\WebKitLibraries\win\include”

    This should solve the error you mentioned (pwin32.h is in WebKit\WebKitLibraries\win\include\unicode) as well as similar file not found errors.

  3. sundar

    Hi Avinash,

    Tats really fantastic. U hav mentioned all the problems tat I have faced and resolved. But bad luck for me .. I dint got to c ur blog initially.
    I was working in porting webkit. Now i was identifying the platform independent files first as part of porting.

    sundar.rahul@gmail.com
    – sundar

  4. sundar

    Hii I m facing this error. can you help me??

    —— Build started: Project: QTMovieWin, Configuration: Debug Win32 ——
    Performing Pre-Build Event…
    svn: ‘.’ is not a working copy
    Compiling…
    QTMovieWin.cpp
    QTMovieWinTimer.cpp
    Generating Code…
    Compiling resources…
    Compiling manifest to resources…
    Linking…
    link: missing operand after `ÿþ/’
    Try `link –help’ for more information.
    Project : error PRJ0002 : Error result 1 returned from ‘C:\cygwin\bin\link.exe’.

  5. Anonymous

    Hi sundar,
    Avishkar has clearly mentioned in his blog to get rid of the cygwin link.exe as it causes conflict with real vc++ linker ..

    Get rid of cygwin’s link.exe in cygwin/bin (rename it or delete it). This causes a conflict with the real linker (VC++’s link.exe). It was likely caused by the order in which VC++ executable directories were set, so if you need it, you might be able to keep it.

    hope this help 🙂

    –DEBUG

  6. jcpark79

    Hello Avishkar Auta,
    2 days ago, I read the post about “Compiling Webkit on Win32” on your blog.

    I think it is ABSOLUTELY BRILLIANT!!

    But unfortunately I still have a few problem.

    I have been following your post on how to set up webkit on windows and have done almostl the required steps.
    ( I didn’t do below steps. Actually I don’t understand exactly what you mean.

    * For the QtMovieWin project, all all source files (there’s only 4) so that windows.h is included first (this is due to macro above, which will now cause a macro redefinition by the preprocessor).
    * For QtMovieWin, also rearrange the order of include, so that #include “wtf/Vector.h” is included before config.h and windows.h to prevent some min/max macro nonsense.
    * For QtMovieWin, take off prompt error reporting for linking (ERRORREPORT:PROMPT) project (see Linker >> Advanced page in project setting).
    * Make a new config file by copying WebCore/config.h and making WebCore/config_qt.h. Remove the ARRAYSIZE macro defintions from config_qt.h. Update all files in QtMovieWin project so that config_qt.h is included instead of config.h.

    )

    Anyway, I tried compiling and had lots of errors and warnings. Next I’d like to show you some of fatal errors. Could you guide me how to solve the problems?

    [A] No such file and directory. : unicode/pwin32.h, pthread.h, sched.h, SVGNames.h, etc..
    – I update VC++ directories and add the following directory: “WebKit\WebKitLibraries\win\include”. but I still have the errors.

    [B] After below messages, there are many errors because CCSValueKeywords.h doesn’t exsit.
    2>perl -ne ‘print lc’ /home/JC47~1.PAR/WebKit/WebCore/css/CSSValueKeywords.in /home/JC47~1.PAR/WebKit/WebCore/css/SVGCSSValueKeywords.in > CSSValueKeywords.in
    2>if sort CSSValueKeywords.in | uniq -d | grep -E ‘^[^#]’; then echo ‘Duplicate value!’; exit 1; fi
    2>Duplicate value!
    2>make: *** [CSSValueKeywords.h] Error 1
    2>make: *** Waiting for unfinished jobs….

    Probably I misunderstood your post and made a few mistakes.

    Please help me in order to come out of this situation.

    Thanks a lot in advance.

    Here is my PC environment.

    + OS : Windows XP – service pack 3
    + Visual Studio 2005 (Korean) and I’ve installed SP1 as well.
    + cygwin
    + Downloaded WebKit Support Libraries.
    + Got the source for nightly build.
    + Windows server 2003 ED. of the Platform SDK
    + QuickTime 7.3 SDK

  7. Avishkar Autar

    [A] Check the “WebKit\WebKitLibraries\win\include” folder to make sure you have the appropriate files (the ones giving you errors in VC++). If files or folders are missing, try running the update-webkit script to get them.

    Things may have also changed since I posted this, so look to see if the files are in another directory (and update your VC++ directories so that VC++ can find them).

    [B] I don’t think there’s a CCSValueKeywords.h or it’s probably generated dynamically and then deleted. This error is likely caused by a previous error, so focus on the missing files errors first.

    For the steps you skipped, sorry, it was a bit confusing, but it’s not too difficult.

    For you have to change the order of your includes.

    For QTMovieWinTimer.cpp,

    the order of your includes should be:

    #include <windows.h>
    #include “config_qt.h”
    #include “QTMovieWinTimer.h”
    #include <wtf/Assertions.h>

    and for QTMovieWin.cpp,

    #include “config_qt.h”
    #include <wtf/Vector.h>
    #include <windows.h>
    #include “QTMovieWin.h”
    #include <Movies.h>
    #include <GXMath.h>
    #include <QTML.h>
    #include “QTMovieWinTimer.h”
    #include <wtf/Assertions.h>
    #include <wtf/HashSet.h>
    #include <wtf/Noncopyable.h>

    Note that you have to make config_qt.h, it’s the same as config.h without the ARRAYSIZE macro.

    Turn off prompt error reporting by right clicking on the QTMovieWin project in VC++’s solution explorer. Go to Linker >> Advanced. Change the “Error Reporting” field to “Default”

  8. Fahd

    Hi there Avishkar,

    – Nice guide you’ve got here since building WebKit with VC++ is a real pain. Well, as you’ve probably guessed I tried to do what you said but had some problems. My problem occur when building the JavaScriptCore project, more precisely when compiling “JSStringRefCF.cpp” : The compiler just throws a bajilion errors about missing “;”, redefinitions etc … in different include files from WebKitSupportLibrary. I tried to change the order of the includes in “JSStringRefCF.cpp” but it didn’t change a thing. Here is how it looks like :

    … here a bunch of source files compile successfully then …

    2>JSStringRefCF.cpp

    2>C:\cygwin\home\admin\WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include\CoreFoundation/CFBag.h(12) : error C2144: syntax error : ‘const void’ should be preceded by ‘;’

    2>C:\cygwin\home\admin\WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include\CoreFoundation/CFBag.h(12) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int

    2>C:\cygwin\home\admin\WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include\CoreFoundation/CFBinaryHeap.h(18) : error C2146: syntax error : missing ‘;’ before identifier ‘CF_EXTERN_C_BEGIN’

    2>C:\cygwin\home\admin\WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include\CoreFoundation/CFBinaryHeap.h(18) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int

    2>C:\cygwin\home\admin\WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include\CoreFoundation/CFBinaryHeap.h(18) : error C2143: syntax error : missing ‘;’ before ”

    2>C:\cygwin\home\admin\WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include\CoreFoundation/CFBinaryHeap.h(18) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int

    2>C:\cygwin\home\admin\WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include\CoreFoundation/CFBinaryHeap.h(18) : error C2086: ‘int CF_EXTERN_C_BEGIN’ : redefinition

    2> C:\cygwin\home\admin\WebKit\WebKitSupportLibrary\WebKitSupportLibrary\win\include\CoreFoundation/CFBag.h(12) : see declaration of ‘CF_EXTERN_C_BEGIN’

    etc … etc …

    – Any guess ? :/

    Thanks in advance 🙂

  9. aautar

    Hey Fahd, sorry it’s been so long since I look at the WebKit code, I can’t really offer any help w/ the issue you posted. The codebase may have also changed a lot since I made this post.

  10. Fahd

    Nevermind, I solved the problem and WebKit has successfully built ! Yay \o/

  11. Great post! Just wanted to let you know you have a new subscriber- me!

  12. Xpert

    when i have build as you mentioned but one problem is coming

    Error 1 fatal error U1077: ‘C:\Utils\Cygwin\bin\bash.EXE’ : return code ‘0x1’ NMAKE
    Error 2 error PRJ0019: A tool returned an error code from “Performing Makefile project actions” JavaScriptCoreGenerated

  13. Rohan

    Hi,
    I’m still getting the errors – CSSValueKeywords.h file not found.

  14. arjun

    @fadh:What was the problem.
    because mine is the same error.

  15. arjun

    I’m still getting the errors in CFBag.h