SoftwareNetwork / sw

Software Manager. Build System, Build System Generator and Package Manager. C/C++ and other languages. Tools and libraries for Software Management.
https://software-network.org
Other
118 stars 24 forks source link

Trying to Build tesseract - Errors from SW #115

Open FlyinTeller opened 1 year ago

FlyinTeller commented 1 year ago

Describe the bug I am trying to build tesseract directly from source. I have cloned the github repo and am running sw --trace build in the main directory. See the output in the attached file

Expected behavior Installation without error

To Reproduce Steps to reproduce the behavior:

  1. Clone https://github.com/tesseract-ocr/tesseract.git
  2. cd tesseract
  3. sw --trace build

Information:

rsnitsch commented 1 year ago

I am integrating tesseract into my project and get a build error, too:

(...)
[131/140] [org.sw.demo.boost.filesystem-1.81.0].lib
Exception in file D:/dev/cppan2/client2/src/sw/builder/command.cpp:840, function execute1: When executing: [pub.egorpugin.primitives.command-0.3.1]/src/command.cpp
C:/Users/Robert/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(142): error C2039: "contains" ist kein Member von "std::basic_string<char,std::char_traits<char>,std::allocator<char>>".
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xstring(4905): note: Siehe Deklaration von "std::basic_string<char,std::char_traits<char>,std::allocator<char>>"
C:/Users/Robert/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(147): note: Siehe Verweis auf die gerade kompilierte Instanziierung "auto primitives::Command::setProgram::<lambda_1>::()::<lambda_1>::operator ()<const char(&)[6]>(_T1) const" der Funktions-Vorlage.
        with
        [
            _T1=const char (&)[6]
        ]

Relevant part of my CMakeLists.txt:

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Add Tesseract via SW
# Source: https://github.com/SoftwareNetwork/sw/tree/master/test/integrations/cmake/tess
set(SW_BUILD_SHARED_LIBS 1)
set(DEPENDENCIES
    org.sw.demo.google.tesseract.libtesseract-master
)
find_package(SW REQUIRED)
sw_add_package(${DEPENDENCIES})
sw_execute()
FlyinTeller commented 1 year ago

I resorted to building tesseract from source with -DSW_BUILD=False and manual installing of neccessary dependencies

egorpugin commented 1 year ago

Use the latest VS2022. I might need to update sw binary first to make it work.

livezingy commented 1 year ago

I get the same error when I compile the tesseract5.3.1 on VS1019&win11 with sw. Then I compile the tesseract5.3.1 X64 successfully with vcpkg, cmake and command prompt on win11 refer to workflows/vcpkg.yml

rsnitsch commented 1 year ago

Use the latest VS2022. I might need to update sw binary first to make it work.

Unfortunately, I cannot easily switch to VS 2022, because that breaks compatibility with another library that I use (OpenCV). When I try to use VS 2022 then CMake reports: Found OpenCV Windows Pack but it has no binaries compatible with your configuration. You should manually point CMake variable OpenCV_DIR to your build of OpenCV library.

I could compile OpenCV myself with VS 2022 as well, but currently I don't have the time for that.

For now I have resorted to using the tesseract binaries by Uni Mannheim and calling tesseract.exe as a subprocess (saving image file and providing the path to that).

egorpugin commented 1 year ago

I mean, that you need to install VS2022 for sw. For your purposes you are free to use any version you need.

rsnitsch commented 1 year ago

I get a new error now:

ninja: error: 'C:/Users/Robert/.sw/storage/pkg/b1/62/8e34/obj/bld/485381/lib/org.sw.demo.google.tesseract.libtesseract-5.3.1.lib', needed by 'CMakeFiles/MYPROJECT_autogen_timestamp_deps', missing and no known rule to make it

My CMakeLists.txt:

# Add Tesseract via SW
# Source: https://github.com/SoftwareNetwork/sw/tree/master/test/integrations/cmake/tess
set(SW_BUILD_SHARED_LIBS 1)
set(SW_DEPENDENCIES
    org.sw.demo.google.tesseract.libtesseract-5.3.1
)
find_package(SW REQUIRED)
sw_add_package(${SW_DEPENDENCIES})
sw_execute()

# ...

target_link_libraries(MYPROJECT PRIVATE
    # other deps...
    ${SW_DEPENDENCIES}
)

I tried to remove the line with SW_BUILD_SHARED_LIBS but it doesn't change anything.

sw version:

λ sw --version
sw.client.sw version 1.0.0
git revision 30611200c2168a3ca7f9d888c11ba375b4667d07
assembled on
13.06.2023 21:33:07 UTC
13.06.2023 23:33:07 Mitteleurop�ische Sommerzeit

Visual Studio 2019 and 2022 are installed and up-to-date. I also have the Visual Studio 2017 build tools installed and updated.

egorpugin commented 1 year ago

Hi,

I'm not sure that Ninja generator works with sw. I tried your example and see

d:\dev\cppan2\client2\test\integrations\cmake\tess\ninja>cmake --build .
ninja: error: 'D:/dev/swst/pkg/b0/7f/f40a/obj/bld/108430/lib/org.sw.demo.google.tesseract.libtesseract-5.3.2.lib', needed by 'tess_example.exe', missing and no known rule to make it

Try to build using VS generator.

egorpugin commented 1 year ago

I've made a fix for Ninja. https://github.com/SoftwareNetwork/sw/commit/7d2916a1aac00edfb0fb917ade42a23a5fcc7a85#diff-680a0d8c76eec8315c509b457b47195fd59aa97dcf5c70cad13e2e080d4f0074R331

Try to add following lines (without version change in the top) into C:\users\u\.sw\storage\static\SWConfig.cmake

rsnitsch commented 1 year ago

Sorry @egorpugin I am now using vcpkg to integrate tesseract.

My CMakeLists.txt now looks like this:

# Make vcpkg install all binaries (DLLs)
set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)

# Setting the toolchain did not work, so I include the vcpkg CMake script directly.
include(C:/vcpkg/scripts/buildsystems/vcpkg.cmake)

find_package(Tesseract REQUIRED)
include_directories( ${Tesseract_INCLUDE_DIRS} )

target_link_libraries(MYPROJECT PRIVATE
    Tesseract::libtesseract
)
MK-3PP commented 1 year ago

Use the latest VS2022. I might need to update sw binary first to make it work.

Workaround to not buying the newest compiler for just sw or tesseract: In your user path, then /.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp Relpace line 142 return s.contains("4nt.exe"); with return s.find("4nt.exe") != std::string::npos; Some very quick fella included C++23 there.

egorpugin commented 1 year ago

Workaround to not buying the newest compiler for just sw or tesseract:

Is it possible to use VS 2022 build tools? Are they free?

MK-3PP commented 1 year ago

Idk, the community versions should be available. As for my case, the dev and build systems in our company run on VS 2019 Pro Licenses and I doubt CEOs and admins will be very happy to break the ecosystem for just this one line.

(We will upgrade eventually, but not for this.)