(Optional) Building the leptonlib library

Assuming that you’ve downloaded or built the requisite image libraries, building leptonlib itself is straightforward since a Visual Studio solution file is provided.

  1. Download the latest version of leptonica from here. Extract the archive to the BuildFolder directory. You should now have:

    BuildFolder\
      giflib-4.1.6\
      include\
      jpeg-8b\
      leptonlib-1.67\
      lib\
      libtiff-3.9.4\
      lpng143\
      zlib\
    
  2. Download the Microsoft Visual Studio 2008 build package from here. Extract the archive to the BuildFolder\leptonlib-1.67 directory. You should now have:

    BuildFolder\
      include\
      leptonlib-1.67\
        vs2008\
      lib\
      tiff-3.9.4\
    
  3. leptprotos.h has the wrong declaration for setPixMemoryManager() under Windows. Change it from:

    LEPT_DLL extern void setPixMemoryManager ( void * ( allocator (size_t ) ), void  ( deallocator ( void * ) ) );
    

    to:

    LEPT_DLL extern void setPixMemoryManager (void *((*allocator)(size_t)), void ((*deallocator)(void *)) );
    
  4. Copy all the .h header files from leptonlib-1.67\src to BuildFolder\include\leptonica.

  5. Open BuildFolder\leptonlib-1.67\vs2008\leptonlib.sln with Visual Studio 2008.

  6. Select the desired build configuration (either LIB Debug, LIB Release, DLL Debug, or DLL Release and probably Win32).

    LIB Debug builds use the following C compiler options:

    /Od /I "..\..\include"
    /D "WIN32" /D "_DEBUG" /D "_LIB" /D "L_LITTLE_ENDIAN"
    /D "snprintf=_snprintf" /D "XMD_H"
    /FD /EHsc /RTC1 /MDd /Fo"LIB Debug\\" /Fd"LIB Debug\vc90.pdb"
    /W3 /nologo /c /Z7 /errorReport:prompt
    

    LIB Release builds use the following C compiler options:

    /O2 /I "..\..\include"
    /D "WIN32" /D "NDEBUG" /D "_LIB" /D "L_LITTLE_ENDIAN"
    /D "snprintf=_snprintf" /D "XMD_H" /D "NO_CONSOLE_IO"
    /FD /EHsc /MD /Fo"LIB Release\\" /Fd"LIB Release\vc90.pdb"
    /W3 /nologo /c /errorReport:prompt
    

    DLL Debug builds use the following C compiler options:

    /Od /I "..\..\include"
    /D "WIN32" /D "_DEBUG" /D "_USRDLL" /D "_WINDLL"
    /D "LEPTONLIB_EXPORTS" /D "L_LITTLE_ENDIAN"
    /D "snprintf=_snprintf" /D "XMD_H"
    /FD /EHsc /RTC1 /MDd /Fo"DLL Debug\\" /Fd"DLL Debug\vc90.pdb"
    /W3 /nologo /c /Z7 /errorReport:prompt
    

    DLL Release builds use the following C compiler options:

    /O2 /I "..\..\include"
    /D "WIN32" /D "NDEBUG" /D "_USRDLL" /D "_WINDLL"
    /D "LEPTONLIB_EXPORTS" /D "L_LITTLE_ENDIAN"
    /D "snprintf=_snprintf" /D "XMD_H" /D "NO_CONSOLE_IO"
    /FD /EHsc /MD /Fo"DLL Release\\" /Fd"DLL Release\vc90.pdb"
    /W3 /nologo /c /errorReport:prompt
    

    All configurations turn off some warnings with the following options:

    /wd4244 /wd4305 /wd4018 /wd4267 /wd4996
    
  7. Right-click leptonlib-1.67 in the Solution Explorer and Choose Build or Rebuild from the context menu (Choosing Build ‣ Build Solution (F6) or Build ‣ Rebuild Solution from the Visual Studio menubar will result in ioformats_reg also being built). The resultant library will automatically be copied to BuildFolder\lib.

    The libraries are named as follows:

     

    Debug Builds

    Release Builds

    Static library

    leptonlib-static-mtdll-debug.lib

    leptonlib-static-mtdll.lib

    DLL

    leptonlibd.lib (import library)
    leptonlibd.dll
    leptonlib.lib (import library)
    leptonlib.dll