Friday 5 July 2013

Code reviews of horrors

This made me bang my head on my desk so hard I almost broke my glasses:

lock (new Object())
{
    // Code exprected to be thread safe...
}

Don't think it needs more explantation.

Wednesday 15 May 2013

Building Cairomm on windows

Just a quick post to document the few troubles I had building cairomm on Window. Here is my setup:
- Windows 8
- Visual Studio express 2012

I started using this awesome post that details the procedure step by step. It's globally still valid but as time goes there are a few tweaks that have to be done. Here is an updated procedure.

Setup

Install MinGW. Assuming you installed MinGW in "C:\MinGW" type the following command to install MSYS and all the tools for development:
mingw-get install msys-dvlpr

Download the sources for the following components:
- zlib
- libpng
- pixman
- cairo
- libsigc++
- cairomm
I recommend decompressing the source trees in the same directory next to each other, and removing the version information. For example rename the libpng-1.5.15 directory to just libpng. It will save some Makefile edition.

Open a cmd.exe terminal and run "c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat". This will set-up the proper environment for building with Visual Studio tools.

Building Zlib

Go in Zib directory and run:
nmake /f win32\Makefile.msc

Building libPNG

Go in libPNG directory and run:
nmake /f scripts\makefile.vcwin32
The script is hard coded to find zlib and will work if you named the directory as told.

Building pixman

Now we have to use MSYS. The Makefile will still use VS compiler, but it is not suitable for nmake. Open a MSYS console by running the command:
c:\MinGW\msys\1.0\msys.bat
In this console navigate to you sources directory (use "cd /c/Path" instead of "cd C:\Path"). Go in the pixman sources an run:
make -f Makefile.win32

Building Cairo

Still in the MSYS console, go in the Cairo sources directory and run:
make -f ../Makefile-cairo.win32 CFG=release

Build libsigc++

Now we are going to use Visual Studio for building our components. You can just open and build the project using libsigc++\MSVC_Net2010\libsigc++2.sln

Building Cairomm

Now is the build part. We have to manually configure the Visual Studio project in cairomm\MSVC_Net2010\cairomm.sln.
In Configuration Properties>C/C++>Genereal>Additional Include Directories add path to:
- cairo\src
- libsig++
- libsig++\MSVC_Net2010
In Configuration Properties>Linker>Genereal>Additional Library Directories add :
- cairo\src\release
- libpng
- zlib
- libsigc++\MSVC_Net2010\Win32\Release
In Configuration Properties>Linker>Input>Additional Dependencies add :

- cairo.lib
- libpng.lib
- zlib.lib
- msimg32.lib
- sigc-vc100-2_0.lib


When building cairomm-1.10.0 I had the following error:

Error 11 error LNK2019: unresolved external symbol "public: __thiscall Cairo::Device::Device(struct _cairo_device *,bool)" (??0Device@Cairo@@QAE@PAU_cairo_device@@_N@Z) referenced in function "public: class Cairo::RefPtr<class Cairo::Device> __thiscall Cairo::Surface::get_device(void)" (?get_device@Surface@Cairo@@QAE?AV?$RefPtr@VDevice@Cairo@@@2@XZ) C:\Users\antoine\Documents\Visual Studio 2012\Projects\PuillotPouillot\cairomm\MSVC_Net2010\cairomm\surface.obj cairomm-1.0

After investigation it turns out there was a missing file in the solution. In project cairomm-1.0 under Source Files click Add>Existing Item... and select the file cairomm/device.cc. This should fix the problem and end building the project.

Hope this will help.