Compiling WebKit/Cairo on Windows with Visual C++ Express

Just for interest, I decided to build webkit on Windows. This supposed to be a painless task but unfortunately, anything that involves build scripts creates drama. The instructions on compiling are a bit scant, giving the impression that it’s super easy. Maybe it is and I’m just a bit dumb, but anyways after a few hours battling with it I finally got it working. Don’t bother trying with Visual Studio 2008 as you might as well jump off a cliff from compilation errors – Get the Visual C++ Express 2005 edition and SP1 patch. Here are the steps from scratch:

Go to http://nightly.webkit.org/ and get the source tar.bz2.

Extract it somewhere (WinRAR is a good tool for this). This somewhere will now be referred to as {EXTRACTED}.

For compiling on windows, you need windows Download the WebKitSupportLibrary.zip then copy this zip file on the root of your extracted webkit folder. Don’t extract it. This zip gives you unicode/uchar.h or pthread.h which would otherwise be reported missing.

So what’s the difference between webkit/cairo and regular webkit? The regular webkit depends on proprietary Apple libraries such as CoreGraphics. The webkit/cairo build substitutes that dependency with the free Cairo 2D graphics library. The library has a clean C API and contains very compehensive drawing routines. It also sports multiple output backends allowing you to create PDFs or SVGs.

Webkit/cairo has more dependencies on open source libraries such as curl. You either build them or get the pre-built ones some nice folks have put online – Get it here and extract it to a place like {EXTRACTED}\requirements.

Now you have to install Cygwin as noted here on point number 3. The important point I want to highlight is due to some assumptions made in the VS project files, the directory HAS to be: at c:\cygwin (or $(SYSTEMROOT)\cygwin). For Vista, you need to perform additional minor gymnastics which I’m not going to outline here. Read it on the previous link.

You also need to get the Quick Time SDK. Annoyingly, to download quicktime SDK you need to register a Apple Developer Connection (ADC) account. After entering details of your daily life, you’re grant access to the file. Good thing was that you don’t need quick time or itunes installed. You should probably keep the default install directory as well.

Next is setting two environment variables. This involves going into the System Properties in your Control Panel. You can just put add it under the User variables:

  • WEBKITLIBRARIESDIR – point it to your {EXTRACTED}\WebKit\WebKitLibraries\win
  • WEBKITOUTPUTDIR – point it somewhere like c:\webkitdist (create this directory as well)

You will now need to add some VC++ paths. Open C++ Express and go to Tools > Options > Projects > VC++ Directories

On the top drop down, select show directories for include files and add

  • {EXTRACTED}\requirements\include
  • {EXTRACTED}\requirements\include\cairo
  • {EXTRACTED}\requirements\include\curl
  • {EXTRACTED}\requirements\include\libpng13

then select show directories for library files and add

  • {EXTRACTED}\requirements\lib

Lastly in the Executables files section add

  • C:\cygwin\bin – Put this just above $(PATH) but after all the other directories. This is important as if you put it on top, cygwin’s link.exe will conflict with MSVC’s, and you need to put it above $(PATH) or the PATH directories that have similarly named binaries to cygwin’s will conflict.

You will also need to get the Platform SDK as noted in the build instructions if you don’t have it already. Any recent version of the SDK should be alright. Add the executable, include and lib directories to the VC++ directories like the above, described here. The instructions about vcprops editing aren’t really important.

For the include path, you also need to add the mfc includes or the compiler will complain about missing winres.h

Due to some bootstrapping scripts, the first time you compile you can’t do it through the Visual C++ IDE. You will need to compile it via the command line in cygwin. Open the cygwin shell and change directory to {EXTRACTED} ie cd c:/webkit/

Then run:

WebkitTools/Scripts/update-webkit

After it completes, you can start building

WebkitTools/Scripts/build-webkit --cairo-win32 --debug

Remove the –debug flag if you want to compile for Release.

After the first successful build, you can now open {EXTRACTED}\WebKit\win\WebKit.vcproj in Visual Studio. Make sure the build profile is set to Debug_Cairo, set it. You can choose Release_Cairo as well if you so wish. Fianlly, winlauncher is the test browser you use to try out your new build, so set that as your active project. Don’t forget to copy all the requirements dlls (ie cairo.dll) into the dist\bin folder where winlauncher.exe is or else it’ll complain about missing DLLs.

Tags: , , ,

9 Responses to “Compiling WebKit/Cairo on Windows with Visual C++ Express”

  1. Malma says:

    Thanks a lot for your post! it was very helpful.

  2. Cesar Romero says:

    Hi, Can you provide the Compiled WebKit dll?

    Thanks.

  3. Ambrose J says:

    Hi ,

    Can I develop a webkit based standalone application for windows ? If yes any links to follow

  4. Loune says:

    You can follow the example of the “winlauncher” project that’s in the webkit source package. It’s a very basic win32 web browser. If you are using .NET, you might want to check out WebKit.NET

  5. pleonex says:

    The Visual C++ Express 2005 download link is wrong, in the current link you can download Visual C# IDE.

  6. Loune says:

    @pleonex Thanks for noticing this. Here’s the correct link for Visual C++ 2005
    http://go.microsoft.com/fwlink/?linkid=57034

  7. sonu says:

    Why doesn’t someone make a single .DLL file that can loaded at runtime and make some functions like EmbedBrowser(HWND control), Navigate(“some text”) etc etc.

    That would make it soooo easy to embed the damn thing into any win32 app!!!

  8. Hi Loune,

    Thank you very much for your detailed post. It was very helpful.
    Just wanted to alert future audience that, even if they have cygwin already installed, they should use the cygwin as provided in webkit repo (http://svn.webkit.org/repository/webkit/trunk/WebKitTools/CygwinDownloader/cygwin-downloader.zip) as pointed by you, to be certain about the dependencies. I am using Windows 7 and had cygwin already installed, I killed about 3 hours to know that there is some issue with my cygwin. Downloading the one from webkit’s repo fixed the issue immediately.
    The error I was seeing was weird, “Cannot write to file…”. Arbitrarily some of the basic file operations were failing, when tried the webkit-update.

    Anyways, the moral is stick to every step as documented, you will have your own webkit with fewer hassles.

    Thanks once again for this post.

    +ramki

Leave a Reply