leptonica
leptonica copied to clipboard
Feature request: Static linking of external dependencies on Windows
Leptonica build with cppan on Windows creates a lot of dll with strange names (pvt.cppan.demo...,dll) that need to be distributed together with leptonica dll...
I would prefer to have just leptonica.dll without need to distribute all its dependencies (png, tiff, z, jpeg...) . This should be possible to do with static linking of all used libraries...
Try this: https://github.com/Phreak87/LeptonicaSharp/issues/2
@egorpugin
I'd bet that you have an opinion on this :-)
On TODO list :)
@tdhintz : It looks promising. I tried this:
cppan --clear-cache --clear-vars-cache
mkdir build64 & cd build64
set CPPAN_USE_CACHE=0
cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX="F:/win64/" -DCPPAN_BUILD_SHARED_LIBS=0
cmake --build . --config Release --target install
and result was:
...
-- Install configuration: "Release"
-- Installing: F:/win64/lib/pkgconfig/lept.pc
-- Installing: F:/win64/cmake/LeptonicaConfig.cmake
-- Installing: F:/win64/cmake/LeptonicaConfig-version.cmake
-- Installing: F:/win64/lib/pvt.cppan.demo.webmproject.webp-1.0.0.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.xz_utils.lzma-5.2.4.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.gif-5.1.4.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.jpeg-9.2.0.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.mgk25.jbig.ar-2.1.0.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.tiff-4.0.9.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.openjpeg.openjp2-2.3.0.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.madler.zlib-1.2.11.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.mgk25.jbig.jbig-2.1.0.lib
-- Installing: F:/win64/lib/pvt.cppan.demo.png-1.6.35.lib
-- Installing: F:/win64/lib/leptonica-1.77.0.lib
-- Installing: F:/win64/bin/leptonica-1.77.0.dll
...
So part of dependencies is installed anyway...
There should be an option to disable copy of lib files (not 100% sure).
Try copy_import_libs: false
https://github.com/tesseract-ocr/tesseract/blob/master/cppan.yml#L7
thanks.
I found a problem ;-): When I tried to use this library in tesseract:
- I configured tesseraact like this:
cmake .. -DCPPAN_BUILD=OFF -DBUILD_TRAINING_TOOLS=OFF -DCMAKE_PREFIX_PATH=f:\win64
- I compiled it with:
cmake --build . --config Release --target install
- Build finish with linking error:
LINK : fatal error LNK1181: cannot open input file 'pvt.cppan.demo.gif.lib'
and it is true, because inf:\win64\lib
there ispvt.cppan.demo.gif-5.1.4.lib
. If I got it right, the information about wrong library names comes fromf:\win64\cmake\LeptonicaTargets-release.cmake
I've removed cppan from leptonica (as from tess). Cmake uses sw now. Could you try your steps?
mkdir build && cd build
# download sw, add to path
sw setup # for cmake integration
cmake .. && cmake --build .
^ must build release lept with statically linked deps
@egorpugin is it not possible to build a DLL with static linking of external dependencies with SW?
With CPPAN I was able to achieve this by using CMAKE with the following -DCPPAN_BUILD_SHARED_LIBS=0, but with SW and CMAKE -DSW_BUILD_SHARED_LIBS=0 will only output a static lib. I can compile a Leptonica DLL with all of the external dependencies in separate DLL files, but would greatly prefer to only have one DLL that contains all of the external dependencies. Thank you for your work on this project!
@rweldin
Seems a bug. Thank you! (Fix in https://github.com/SoftwareNetwork/sw/commit/4f72f4044ac997b0022cf1030112aba0dbdf828c)
Re-download sw (sw --self-upgrade
or from the website).
Update cmake integration sw setup
.
Run:
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=1 -DSW_BUILD_SHARED_LIBS=0 ..
cmake --build .
Works for me now.
@egorpugin thank you for the quick fix. After upgrading SW I was able to build Leptonica with static linking of the external dependencies.
@egorpugin These steps fail for me using VS 2019. Suggestions?
Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 5/29/2020 4:19:29 PM.
Project "D:\Petri\41b\leptonica\build\CMakeFiles\3.11.0-rc3\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(390,5): error MSB8020: The build tools for Visual Studio 2017 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install Visual Studio 2017 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [D:\Petri\41b\leptonica\build\CMakeFiles\3.11.0-rc3\VCTargetsPath.vcxproj]
Done Building Project "D:\Petri\41b\leptonica\build\CMakeFiles\3.11.0-rc3\VCTargetsPath.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\Petri\41b\leptonica\build\CMakeFiles\3.11.0-rc3\VCTargetsPath.vcxproj" (default target) (1) ->
(PrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(390,5): error MSB8020: The build tools for Visual Studio 2017 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install Visual Studio 2017 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [D:\Petri\41b\leptonica\build\CMakeFiles\3.11.0-rc3\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
CMakeFiles\3.11.0-rc3
Can you try to update cmake to 3.17.2?
That was it. Thanks for your patience.
Seems to target a Debug build. Am I missing a step?
D:\Petri\41b\leptonica\build>cmake --build .
Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
sw: building dependencies
leptonica.vcxproj -> D:\Petri\41b\leptonica\build\bin\Debug\leptonica-1.80.0d.dll
Default is Debug build IIRC.
Use cmake --build . --config Release
.