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 --wincairo --debug

Remove the –debug flag if you want to compile for Release. Note: Previously the wincairo flag was cairo-win32.

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. Finally, 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.

29 thoughts on “Compiling WebKit/Cairo on Windows with Visual C++ Express

  1. Loune Post author

    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

  2. pleonex

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

  3. sonu

    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!!!

  4. Ramki Gaddipati

    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

  5. Daebark

    Hello,

    Thanks a lot! I can build webkit now.
    Now, I want to run WinLauncher_debug.exe.
    Only one problem is that I cannot find the right cairo.dll.
    From cairo homepage, I downloaded libcairo-2.dll, zlib1.dll, libpng14-14.dll, and put other requirements folder dlls on webkitdist/bin/.
    Additionally, I’ve tried to renamed it like cairo.dll.
    Nothing happened.
    Where can I get cairo.dll?

  6. Rajesh

    Hello,
    I couldn’t build webkit. It is throwing me error, which i have given below.
    Can u please help me to build webkit.

    In Cygwin prompt
    =================
    vrajesh@pcch-vrajesh /cygdrive/c/cygwin/home/vrajesh/WebKit
    $ WebkitTools/Scripts/build-webkit –cairo -win32 –debug
    0 byte sized file removed from build directory: /cygdrive/c/WebKit/webkitdist/De
    bug
    Generating derived sources

    Calling ‘qmake -r –cairo -win32 OUTPUT_DIR=/cygdrive/c/WebKit/webkitdist/Debug
    -r /cygdrive/c/cygwin/home/vrajesh/WebKit/DerivedSources.pro -o Makefile.Derived
    Sources’ in /cygdrive/c/WebKit/webkitdist/Debug

    ***Unknown option –cairo
    Usage: D:\SVN\qmake.exe [mode] [options] [files]

    QMake has two modes, one mode for generating project files based on
    some heuristics, and the other for generating makefiles. Normally you
    shouldn’t need to specify a mode, as makefile generation is the default
    mode for qmake, but you may use this to test qmake on an existing project

    Mode:
    -project Put qmake into project file generation mode
    In this mode qmake interprets files as files to
    be built,
    defaults to *.c; *.ui; *.y; *.l; *.ts; *.xlf; *.qrc; *.h; *.hpp
    ; *.hh; *.hxx; *.cpp; *.cc; *.cxx
    Note: The created .pro file probably will
    need to be edited. For example add the QT variable to
    specify what modules are required.
    -makefile Put qmake into makefile generation mode (default)
    In this mode qmake interprets files as project files to
    be processed, if skipped qmake will try to find a project
    file in your current working directory

    Warnings Options:
    -Wnone Turn off all warnings
    -Wall Turn on all warnings
    -Wparser Turn on parser warnings
    -Wlogic Turn on logic warnings

    Options:
    * You can place any variable assignment in options and it will be *
    * processed as if it was in [files]. These assignments will be parsed *
    * before [files]. *
    -o file Write output to file
    -unix Run in unix mode
    -win32 Run in win32 mode
    -macx Run in Mac OS X mode
    -d Increase debug level
    -t templ Overrides TEMPLATE as templ
    -tp prefix Overrides TEMPLATE so that prefix is prefixed into the value
    -help This help
    -v Version information
    -after All variable assignments after this will be
    parsed after [files]
    -norecursive Don’t do a recursive search
    -recursive Do a recursive search
    -set Set persistent property
    -query Query persistent property. Show all if is empty.
    -cache file Use file as cache [makefile mode only]
    -spec spec Use spec as QMAKESPEC [makefile mode only]
    -nocache Don’t use a cache file [makefile mode only]
    -nodepend Don’t generate dependencies [makefile mode only]
    -nomoc Don’t generate moc targets [makefile mode only]
    -nopwd Don’t look for files in pwd [project mode only]
    Failed while running qmake to generate derived sources!
    =================

    please help me. i tried lot to find. but i couldn’t get it.

  7. Loune Post author

    @Daebark you shouldn’t need cairo.dll as it should be statically built from cairo.lib in requirements.zip

    @Rajesh the build command is dash dash cairo dash win32 with no space (--cairo-win32) and also dash dash debug

  8. Rajesh

    Hi Loune,
    Sorry for wrong command which i pasted in my last question.
    I typed the command properly as given in the build steps above.

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

    Since it gave error i tried with different combination of single dash, single space like given below.
    1. WebkitTools/Scripts/build-webkit -cairo-win32 -debug
    2. WebkitTools/Scripts/build-webkit -cairo -win32 -debug
    3. WebkitTools/Scripts/build-webkit -cairo -debug

    But it gave the same error for all commands. So i pasted mistakenly wrong command.

    I dont know the below error will be helpful to figureout my issue.
    If i give command without parameters like “$ WebkitTools/Scripts/build-webkit”
    ————————–
    vrajesh@pcch-vrajesh /cygdrive/c/cygwin/home/vrajesh/webkit
    $ WebkitTools/Scripts/build-webkit
    0 byte sized file removed from build directory: /home/vrajesh/WebKit/webkitdist/
    Release
    Generating derived sources

    Calling ‘qmake -r OUTPUT_DIR=/home/vrajesh/WebKit/webkitdist/Release -r /cygdriv
    e/c/cygwin/home/vrajesh/webkit/DerivedSources.pro -o Makefile.DerivedSources’ in
    /home/vrajesh/WebKit/webkitdist/Release

    Cannot find file: \cygdrive\c\cygwin\home\vrajesh\webkit\DerivedSources.pro.
    Failed while running qmake to generate derived sources!
    ————————–
    Please help me. I tried all ways to build it. But its eating my brain & i was struckup with this build for last 2 weeks.

  9. Rajesh

    Hi Loune,
    Sorry for wrong command which i pasted in my last question.
    I typed the command properly as given in the build steps above.

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

    Error:
    ***Unknown option –cairo-win32
    Usage: D:\SVN\qmake.exe [mode] [options] [files]

    Since it gave error i tried with different combination of single dash, single space like given below.
    1. WebkitTools/Scripts/build-webkit -cairo-win32 -debug
    2. WebkitTools/Scripts/build-webkit -cairo -win32 -debug
    3. WebkitTools/Scripts/build-webkit -cairo -debug

    But it gave the same error for all commands. So i pasted mistakenly wrong command.

    I dont know the below error will be helpful to figureout my issue.
    If i give command without parameters like “$ WebkitTools/Scripts/build-webkit”
    ————————–
    vrajesh@pcch-vrajesh /cygdrive/c/cygwin/home/vrajesh/webkit
    $ WebkitTools/Scripts/build-webkit
    0 byte sized file removed from build directory: /home/vrajesh/WebKit/webkitdist/
    Release
    Generating derived sources

    Calling ‘qmake -r OUTPUT_DIR=/home/vrajesh/WebKit/webkitdist/Release -r /cygdriv
    e/c/cygwin/home/vrajesh/webkit/DerivedSources.pro -o Makefile.DerivedSources’ in
    /home/vrajesh/WebKit/webkitdist/Release

    Cannot find file: \cygdrive\c\cygwin\home\vrajesh\webkit\DerivedSources.pro.
    Failed while running qmake to generate derived sources!
    ————————–
    Please help me. I tried all ways to build it. But its eating my brain & i was struckup with this build for last 2 weeks.

  10. Rajesh

    Hi Loune,
    I have pasted double hyphen(–) only in my last question. But it seems like single hyphen(-). I did according to the post & steps given above.

    Thanks,
    Rajesh

  11. Loune Post author

    @Rajesh I just looked at the latest sources and it seems the cairo flag has been changed to --wincairo Try that flag instead. It might also help to run --clean before you retry. As you found out, the guide is a bit dated, so you might still run into other issues. Good luck.

  12. Rajesh

    Hi Loune,
    Still it gives error. I feel i am consuming your precious time. soo sorry for it.
    ——————–
    vrajesh@pcch-vrajesh /cygdrive/c/webkit
    $ WebkitTools/Scripts/build-webkit –wincairo –debug
    0 byte sized file removed from build directory: /cygdrive/c/webkitdist/Debug_Cai
    ro
    Generating derived sources

    Calling ‘qmake -r OUTPUT_DIR=/cygdrive/c/webkitdist/Debug_Cairo -r /cygdrive/c/w
    ebkit/DerivedSources.pro -o Makefile.DerivedSources’ in /cygdrive/c/webkitdist/D
    ebug_Cairo

    Cannot find file: \cygdrive\c\webkit\DerivedSources.pro.
    Failed while running qmake to generate derived sources!
    ————
    Note: If we didnt add -win32 in the command, it gives above error else
    ***Unknown option –cairo-win32
    Usage: D:\SVN\qmake.exe [mode] [options] [file]
    irrespective of cairo parameter –cairo or –wincairo.

    1. I feel “qmake.exe” file which i am having is the problem. Above guide didn’t mention anything about qmake file. I am using qmake file from QT4.6. Is there any other updated qmake file available which detects cairo commands.
    2. From the above guide. Cairo is added only in the requirements folder. Any install or DLL required for cairo else only requirements folder & adding path to VC directories is enough.

  13. Loune Post author

    @Rajesh I don’t think qmake is required and the presence of it is probably throwing the build scripts off. All you need is MSVC++ 2005 and cygwin. Can you remove qmake (D:\SVN) from the path and try again?

  14. Nimish Nayak

    Thanks a lot for your post! it was very helpful.
    I found it much better than the existing on webkit.org for Building on Cairo’s Window Port :P

    I would like to add only one thing to this.. If you are using Visual Studios 2005 Express Edition By Default Microsoft Visual Studios 2005 Express Edition fails to link to the standard libraries sometimes. Thus you have to open the solution folder of WebKit and Under “Additional Libraries” Include the libraries which are missing in the build log of the respective projects

    Mostly its User32.lib and Gdi32.lib But there are a couple of others too.

  15. Ishaque

    I have followed all the steps that you have mentioned, but I get error when I try to build it.

    I have Microsoft Visual Studio 2005 Express and all the above mentioned packages installed.

    but when I run “$ Tools/Scripts/build-webkit –wincairo –debug”

    it shows following error:
    ERROR: FATAL: Failed to determine the SCM system for either /cygdrive/c/cygwin/h
    ome/Essack/WebKit-r90335 or /cygdrive/c/cygwin/home/Essack/WebKit-r90335/Tools/S
    cripts/webkitpy/common/checkout/scm.

    Kindly shed some light on it.

  16. bfulgham

    Hi everyone! I created the WinCairo port of WebKit, and wanted to point out that most of the above instructions are out of date.

    1. To get the required DLL’s and other elements to build WebKit, you just need to execute: “update-webkit –wincairo”. This will download the appropriate header files, libraries, and binaries and install them in the build path.

    2. WebKit (WinCairo) can build under VS2008 cleanly; you do need different builds of the support files. I posted VS2008 builds on my blog from time to time.

    Thanks for trying out WinCairo. I’d sure love to have other contributors working on it, or at least users who can help file bugs and determine which pieces are not working as expected!

  17. Strumsoft

    Hi Daebark,

    I am facing the same issue that you had, could you please tell me how you fixed this issue.

    Daebark says:
    November 9, 2010 at 1:10 am

    Hello,

    Thanks a lot! I can build webkit now.
    Now, I want to run WinLauncher_debug.exe.
    Only one problem is that I cannot find the right cairo.dll.
    From cairo homepage, I downloaded libcairo-2.dll, zlib1.dll, libpng14-14.dll, and put other requirements folder dlls on webkitdist/bin/.
    Additionally, I’ve tried to renamed it like cairo.dll.
    Nothing happened.
    Where can I get cairo.dll?

  18. Strumsoft

    I have resolved the issues that I had, now I am able to compile and run WinLauncher_Debug.exe

  19. TrailBlazzer

    Hi

    Since I am working on WebKit (Windows Port)
    Should I download WebKit-SVN.zip file or WebKit.tar.bz2 file (Like mentioned in the post)??

  20. Pingback: Building WebKit on Windows » the Void

  21. Pingback: Codekata | flaminghorns.com » Building Webkit on Windows 7 with Visual Studio 2008 Express.

Leave a Reply

Your email address will not be published. Required fields are marked *