Cross Compiling static and shared Win32 version PoDoFo under Debian Lenny

I tried many times to compile Podofo 0.9 and svn trunk under Windows 7 + MinGW32, but always failed(I have successfully compiled static and shared version PoDoFo 0.84 under the same environment). So I decided to do the job under Linux with MinGW cross compiling environment.
After the job, Build MinGW Cross Compiling Environment under Debian Lenny, very first time, I tried to compile PoDoFo 0.9 and svn trunk(r1445), and finally both succeed.
download and unpack
wget http://ncu.dl.sourceforge.net/project/podofo/podofo/0.9/podofo-0.9.0.tar.bz2
tar jxf podofo-0.9.0.tar.bz2

Compile Win32 Static Version
mkdir podofo-0.9.0-win32-static
cd podofo-0.9.0-win32-static
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/mingw/usr/i686-pc-mingw32/share/cmake/mingw-cross-env-conf.cmake ../podofo-0.9.0 -DFREETYPE_INCLUDE_DIR_FT2BUILD:PATH=/opt/mingw/usr/i686-pc-mingw32/include/freetype2 -DFREETYPE_INCLUDE_DIR_FTHEADER:PATH=/opt/mingw/usr/i686-pc-mingw32/include -DFREETYPE_LIBRARY_RELEASE:FILEPATH=/opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a -DWIN32=1 -DCMAKE_INSTALL_PREFIX:PATH=/root/podofo-0.9.0-win32-static
make
make install

Maybe because of the bug of the podofo-0.9.0/cmake/modules/FindFREETYPE.cmake, I had to explicit add the freetype info to cmake, if you execute the following command,
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/mingw/usr/i686-pc-mingw32/share/cmake/mingw-cross-env-conf.cmake ../podofo-0.9.0-win32-static -DWIN32=1 -DCMAKE_INSTALL_PREFIX:PATH=/root/podofo-0.9.0-win32-static
you will get the following error message, even though you have already installed FreeType correctly,

CMake Error at /usr/share/cmake-2.6/Modules/FindPackageHandleStandardArgs.cmake:52 (MESSAGE):
Could NOT find FREETYPE
Call Stack (most recent call first):
cmake/modules/FindFREETYPE.cmake:75 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:354 (FIND_PACKAGE)

and because Linux is case sensitive, so I got the following two error messages,
Scanning dependencies of target ContentParser
[ 57%] Building CXX object test/ContentParser/CMakeFiles/ContentParser.dir/main.cpp.obj
Linking CXX executable ContentParser.exe
/opt/mingw/usr/lib/gcc/i686-pc-mingw32/4.5.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lWS2_32
/opt/mingw/usr/lib/gcc/i686-pc-mingw32/4.5.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lWS2_32
/opt/mingw/usr/lib/gcc/i686-pc-mingw32/4.5.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lWS2_32
collect2: ld returned 1 exit status
make[2]: *** [test/ContentParser/ContentParser.exe] Error 1
make[1]: *** [test/ContentParser/CMakeFiles/ContentParser.dir/all] Error 2
make: *** [all] Error 2

(to solve it, just run the following command
ln -s /opt/mingw/usr/i686-pc-mingw32/lib/libws2_32.a /opt/mingw/usr/i686-pc-mingw32/lib/libWS2_32.a
)
and

Scanning dependencies of target helloworld-base14
[100%] Building CXX object examples/helloworld-base14/CMakeFiles/helloworld-base14.dir/helloworld-base14.cpp.obj
/opt/test/podofo-0.9.0/examples/helloworld-base14/helloworld-base14.cpp:31:21: fatal error: BaseTsd.h: No such file or directory
compilation terminated.
make[2]: *** [examples/helloworld-base14/CMakeFiles/helloworld-base14.dir/helloworld-base14.cpp.obj] Error 1
make[1]: *** [examples/helloworld-base14/CMakeFiles/helloworld-base14.dir/all] Error 2
make: *** [all] Error 2

(

to solve it, just run the following command
ln -s /opt/mingw/usr/i686-pc-mingw32/include/basetsd.h /opt/mingw/usr/i686-pc-mingw32/include/BaseTsd.h

)

and when compiled podofoimg2pdf, another error message met,

Scanning dependencies of target podofoimg2pdf
[ 86%] Building CXX object tools/podofoimg2pdf/CMakeFiles/podofoimg2pdf.dir/podofoimg2pdf.cpp.obj
[ 86%] Building CXX object tools/podofoimg2pdf/CMakeFiles/podofoimg2pdf.dir/ImageConverter.cpp.obj
Linking CXX executable podofoimg2pdf.exe
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_write_raw_data':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:321: undefined reference to
_jpeg_write_raw_data'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_finish_compress':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:328: undefined reference to
_jpeg_finish_compress'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_set_colorspace':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:288: undefined reference to
_jpeg_set_colorspace'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_create_compress':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:265: undefined reference to
_jpeg_CreateCompress'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_set_defaults':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:282: undefined reference to
_jpeg_set_defaults'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_write_tables':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:334: undefined reference to
_jpeg_write_tables'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_set_quality':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:294: undefined reference to
_jpeg_set_quality'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_suppress_tables':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:301: undefined reference to
_jpeg_suppress_tables'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_start_compress':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:307: undefined reference to
_jpeg_start_compress'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function TIFFjpeg_write_scanlines':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:314: undefined reference to
_jpeg_write_scanlines'
collect2: ld returned 1 exit status
make[2]: *** [tools/podofoimg2pdf/podofoimg2pdf.exe] Error 1
make[1]: *** [tools/podofoimg2pdf/CMakeFiles/podofoimg2pdf.dir/all] Error 2
make: *** [all] Error 2

from the message, I know it need Jpeg library, checking podofo-0.9.0-win32-static/tools/podofoimg2pdf/CMakeFiles/podofoimg2pdf.dir/link.txt
/opt/mingw/usr/bin/i686-pc-mingw32-g++ -O3 -DNDEBUG CMakeFiles/podofoimg2pdf.dir/podofoimg2pdf.cpp.obj CMakeFiles/podofoimg2pdf.dir/ImageConverter.cpp.obj -o podofoimg2pdf.exe -Wl,--out-implib,libpodofoimg2pdf.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/opt/test/podofo-win32/src -lpodofo /opt/mingw/usr/i686-pc-mingw32/lib/libz.a /opt/mingw/usr/i686-pc-mingw32/lib/libjpeg.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lWS2_32 /opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a /opt/mingw/usr/i686-pc-mingw32/lib/libpng.a /opt/mingw/usr/i686-pc-mingw32/lib/libz.a /opt/mingw/usr/i686-pc-mingw32/lib/libjpeg.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lWS2_32 /opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a /opt/mingw/usr/i686-pc-mingw32/lib/libpng.a /opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a
it already includes libjpeg.a, I do not know why, but have to append some code to let it works, and finally the content of link.txt is as following,
/opt/mingw/usr/bin/i686-pc-mingw32-g++ -O3 -DNDEBUG CMakeFiles/podofoimg2pdf.dir/podofoimg2pdf.cpp.obj CMakeFiles/podofoimg2pdf.dir/ImageConverter.cpp.obj -o podofoimg2pdf.exe -Wl,--out-implib,libpodofoimg2pdf.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/opt/test/podofo-win32/src -lpodofo /opt/mingw/usr/i686-pc-mingw32/lib/libz.a /opt/mingw/usr/i686-pc-mingw32/lib/libjpeg.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lWS2_32 /opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a /opt/mingw/usr/i686-pc-mingw32/lib/libpng.a /opt/mingw/usr/i686-pc-mingw32/lib/libz.a /opt/mingw/usr/i686-pc-mingw32/lib/libjpeg.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lWS2_32 /opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a /opt/mingw/usr/i686-pc-mingw32/lib/libpng.a -L/opt/mingw/usr/i686-pc-mingw32/lib -ltiff -ljpeg -lz .
and now, the Win32 static version PoDoFo 0.9.0 created and installed into /root/podofo-0.9.0-win32-static folder.
To compile shared version, we need do some modification, by default, /opt/mingw/usr/i686-pc-mingw32/share/cmake/mingw-cross-env-conf.cmake has set BUILD_SHARED_LIBS option as OFF, so you need set it ON
mkdir podofo-0.9.0-win32-shared
cd podofo-0.9.0-win32-shared
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/mingw/usr/i686-pc-mingw32/share/cmake/mingw-cross-env-conf.cmake ../podofo-0.9.0 -DFREETYPE_INCLUDE_DIR_FT2BUILD:PATH=/opt/mingw/usr/i686-pc-mingw32/include/freetype2 -DFREETYPE_INCLUDE_DIR_FTHEADER:PATH=/opt/mingw/usr/i686-pc-mingw32/include -DFREETYPE_LIBRARY_RELEASE:FILEPATH=/opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a -DWIN32=1 -DCMAKE_INSTALL_PREFIX:PATH=/root/podofo-0.9.0-win32-shared -DBUILD_SHARED_LIBS:BOOL=TRUE -DPODOFO_BUILD_SHARED=1
make
make install

and when Creating library file: libpodofo.dll.a will get the same error as podofoimg2pdf, and the solution is also same.

Leave a Reply