(Optional) Building the liblept library

Assuming that you’ve downloaded or built the requisite image libraries, building liblept 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-8c\
      leptonica-1.68\
      lib\
      libtiff-3.9.4\
      lpng143\
      zlib\
    
  2. Download the Microsoft Visual Studio 2008 build package from here. Extract the archive to the BuildFolder\leptonica-1.68 directory. You should now have:

    BuildFolder\
      giflib-4.1.6\
      include\
      jpeg-8c\
      leptonica-1.68\
        vs2008\
      lib\
      libtiff-3.9.4\
      lpng143\
      zlib\
    
  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 leptonica-1.68\src to BuildFolder\include\leptonica.

  5. Open BuildFolder\leptonica-1.68\vs2008\leptonica.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 "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 "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 "LIBLEPT_EXPORTS" /D "L_LITTLE_ENDIAN"
    /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 "LIBLEPT_EXPORTS" /D "L_LITTLE_ENDIAN"
    /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
    

    DLL releases set the following linker options:

    /VERSION:1.68
    
  7. Right-click liblept168 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

    liblept168-static-mtdll-debug.lib

    liblept168-static-mtdll.lib

    DLL

    liblept168d.lib (import library)
    liblept168d.dll
    liblept168.lib (import library)
    liblept168.dll