Most precompiled Windows binaries are made with the MSYS+gcc toolchain. It uses MSVCRT runtime, which is incompatible with Visual C++ 2005/2008.
So, how to go about and compile Cairo 1.6.4 (or later) for Visual C++ only. Including dependencies (png,zlib,pixman).
These steps can build the latest cairo on 2015-11-15 for Visual Studio 2015 community. The debug build is DLL, linking to the DLL version of CRT. The release build is static library, linking to the static link version of CRT and requiring no DLLs.
The build scripts require GNU command line tools. The following steps are tested with GnuWin from Chocolatey. MSYS might also work.
zlib128.zip, lpng1619.zip, cairo-1.14.4.tar.xz, pixman-0.32.8.tar.gz
Extract these archives and rename the directories:
. (my_cairo_build_root)
├─cairo
├─libpng
├─pixman
└─zlib
Do not build. The build script uses MSVCRT that clashes with Visual Studio 2015. Use the generated lib from libpng build.
Edit libpng\projects\vstudio\zlib.props:
<ZLibSrcDir> remove the version number: ..\..\..\..\zlib
<WindowsSDKDesktopARMSupport> change true to false
Open libpng\projects\vstudio\vstudio.sln in Visual Studio and confirm the upgrade. Use the default Debug configuration, and right click project libpng to build. Switch to Release Library configuration and right click project libpng to build.
Edit pixman\Makefile.win32.common:
CFG_CFLAGS = -MD -O2 with CFG_CFLAGS = -MT -O2 (linking to the static link version of CRT in release build)@mkdir with @"mkdir" (there are cmd's builtin mkdir and GnuWin's mkdir, the quotes force the latter to be used)Run Visual Studio x86 Native Command Prompt from start menu:
cd /d my_cairo_build_root
cd pixman\pixman
make -f Makefile.win32
make -f Makefile.win32 CFG=debug
Edit cairo\build\Makefile.win32.common:
CFG_CFLAGS = -MD -O2 with CFG_CFLAGS = -MT -O2
CAIRO_LIBS += $(LIBPNG_PATH)/libpng.lib with CAIRO_LIBS += $(LIBPNG_PATH)/lib/$(CFG)/libpng16.lib. Now, copy the directory libpng\projects\vstudio\Debug into (created) libpng\lib\ and rename it to debug. Copy the directory libpng\projects\vstudio\Release Library into libpng\lib\ and rename it to release.CAIRO_LIBS += $(ZLIB_PATH)/zdll.lib with CAIRO_LIBS += $(LIBPNG_PATH)/lib/$(CFG)/zlib.lib
There are two @mkdir -p $(CFG)/`dirname $<` lines. Replace both of them with:
@"mkdir" -p $(CFG)/$<
@"rmdir" $(CFG)/$<
Edit cairo\build\Makefile.win32.features-h:
@echo with @"echo"
There is an unusable link.exe in GnuWin. Rename C:\GnuWin\bin\link.exe to link_.exe to avoid clash.
Run Visual Studio x86 Native Command Prompt from start menu:
cd /d my_cairo_build_root
cd cairo
make -f Makefile.win32 CFG=debug
make -f Makefile.win32 CFG=release
The last two command will show "Built successfully!" but return error. Ignore them.
Rename back C:\GnuWin\bin\link.exe.
Create a directory include and copy the following headers in:
cairo\cairo-version.h (not cairo\src\cairo-version.h)cairo\src\*.h, excluding cairo\src\cairo-version.h
Add that directory to include path in Visual Studio.
Add cairo\src\$(Configuration) and libpng\lib\$(Configuration) to library path. $(Configuration) will automatically expand to Debug or Release when building.
Put cairo\src\debug\cairo.dll and libpng\lib\debug\libpng16.dll to one of Windows' PATH.
Before #include <cairo.h>, setup the link options:
#ifndef NDEBUG
# pragma comment(lib, "cairo")
#else
#define CAIRO_WIN32_STATIC_BUILD
# pragma comment(lib, "cairo-static")
# pragma comment(lib, "libpng16")
# pragma comment(lib, "zlib")
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With