DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.72k stars 384 forks source link

Build fails under Windows #707

Closed Medalha closed 5 months ago

Medalha commented 11 months ago

Since some of the last modifications to the code, I am no longer able to build Leptonica under Windows 10 22H2. I am using cmake on the command line with Microsoft Visual Studio 2022. The build fails with the following error message:

-- sw: processing dependencies CMake Error at C:/Users/Miguel/.sw/storage/etc/sw/static/SWConfig.cmake:148 (message): Compiler is not implemented: 'MSVC' or '' Call Stack (most recent call first): CMakeLists.txt:213 (sw_execute)

Can someone please help with this issue? Thank you!

Medalha commented 11 months ago

I made some experiments. If I use the main 'CMakeLists.txt' from March 21, the build of library and programs succeeds without error.

The file mentioned above is downloadable from here: https://github.com/DanBloomberg/leptonica/blob/0180cb11e405f766ce1429d6c7fd3acf1eb21f46/CMakeLists.txt

DanBloomberg commented 11 months ago

Thank you for reporting this and doing the experiment to find where it broke.

Diffing those two CMakeLists.txt files, I ge:

44c44
<   LANGUAGES C
---
>   LANGUAGES C CXX
46,50d45
< set(CMAKE_C_STANDARD 17)
< set(CMAKE_C_STANDARD_REQUIRED ON)
< 
< # Standard installation paths
< include(GNUInstallDirs)
234c229
< if(CMAKE_C_COMPILER_ID MATCHES "Clang")
---
> if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
249a245
> include(CheckCXXCompilerFlag)
253a250
>   check_cxx_compiler_flag(${flag_} CXX_HAS${result_})
261c258
<     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
---
>     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
278a276,278
>       endif()
>       if(CXX_HAS${flag_var})
>         set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${flag_}")

Just a guess (I don't do support for the cmake build): your problem is with C_STANDARD 17. Someone will look into this.

Dan

Medalha commented 11 months ago

Thank you!

Medalha commented 11 months ago

I commented these two lines and the problem persists:

set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD_REQUIRED ON)

On the other end, leaving the above lines as they are and resetting a single line from

LANGUAGES C

to

LANGUAGES C CXX

as it was before, enables the build without error.

zdenop commented 11 months ago

leptonica is C project, not C++. So reverting this declaration is a mistake. Windows sw build works: https://github.com/DanBloomberg/leptonica/actions/runs/5844900648/job/15848467357 Clean windows cmake build (without sw) works fine too (see https://github.com/DanBloomberg/leptonica/actions/workflows/cmake-win64.yml)

@egorpugin: do you have any suggestions for this problem?

Medalha commented 11 months ago

I don't have enough knowledge on these matters to evaluate this issue properly. All I know is that I used to build Leptonica (with sw) without any issue and suddenly I couldn't do it anymore, with the error I reported in my first message. It happened after the change in the "CMakeLists.txt" file.

The fact remains that simply changing that line to "LANGUAGES C CXX" enables the correct building of the project. The question is why. Why is this enough?

egorpugin commented 11 months ago

Hi,

Please add CXX language in cmake project command.

Medalha commented 11 months ago

Please add CXX language in cmake project command.

Do you mean the cmake command line? Do you remember the correct syntax? I can search for it, of course.

rajeshja commented 7 months ago

Has there been any change @egorpugin ? I'm trying to build leptonica and it's failing with the following errors:

[143/150] [pub.egorpugin.primitives.command-0.3.1]/src/command.cpp
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/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(142): error C2039: 'contains': is not a member of '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(4871): note: see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(147): note: see reference to function template instantiation 'auto primitives::Command::setProgram::<lambda_1>::()::<lambda_1>::operator ()<const char(&)[6]>(_T1) const' being compiled
        with
        [
            _T1=const char (&)[6]
        ]
C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(147): error C3487: 'bool': all return expressions must deduce to the same type: previously it was 'void'
C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(144): error C3487: 'bool': all return expressions must deduce to the same type: previously it was 'void'
C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(144): error C2562: 'primitives::Command::setProgram::<lambda_1>::()::<lambda_1>::operator ()': 'void' function returning a value
C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(147): note: see declaration of 'primitives::Command::setProgram::<lambda_1>::()::<lambda_1>::operator ()'
C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(147): error C2296: '||': illegal, left operand has type 'void'
C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp(147): error C2297: '||': illegal, right operand has type 'void'
command failed: exit code = 2
Total errors: 1

I've tried changing LANGUAGES C to LANGUAGES C CXX and also tried adding the following:

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

but it seems to make no difference.

egorpugin commented 7 months ago

Hi,

You need the latest Visual Studio if you are building with SW tool.

rajeshja commented 7 months ago

Looks like the dependency with the error uses C++23, for which you need VS 2022. Some changes I found in other forums:

  1. Edit line 142 in C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp (look in the error for the exact location) and change it to return s.find("4nt.exe") != std::string::npos;
  2. In leptonica/CMakeLists.txt, change the line LANGUAGES C to LANGUAGES C CXX
  3. I'm not sure if this is strictly necessary, so if the above two don't work, additionally add the following lines:
    set(CMAKE_CXX_STANDARD 20)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)

    after set(CMAKE_C_STANDARD_REQUIRED ON)

Once command.cpp is compiled, you can remove all these changes.

Medalha commented 7 months ago

When this issue first appeared, I was already using VS 2022.

The mere modification of leptonica/CMakeLists.txt from LANGUAGES C to LANGUAGES C CXX solved the problem.

The problem suddenly disappeared, even with LANGUAGES C only, I don’t know if due to subsequent updates of VS 2022 or due to changes in leptonica.

Anyway, there is no issue anymore. Thank you.

From: Rajesh J Advani @. Sent: 22 de novembro de 2023 15:10 To: DanBloomberg/leptonica @.> Cc: Medalha @.>; Author @.> Subject: Re: [DanBloomberg/leptonica] Build fails under Windows (Issue #707)

Looks like the dependency with the error uses C++23, for which you need VS 2022. Some changes I found in other forums:

  1. Edit line 142 in C:/Users/xxx/.sw/storage/pkg/9d/a6/8d0d/src/sdir/src/command/src/command.cpp (look in the error for the exact location) and change it to return s.find("4nt.exe") != std::string::npos;

  2. In leptonica/CMakeLists.txt, change the line LANGUAGES C to LANGUAGES C CXX

  3. I'm not sure if this is strictly necessary, so if the above two don't work, additionally add the following lines:

set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON)

after set(CMAKE_C_STANDARD_REQUIRED ON)

Once command.cpp is compiled, you can remove all these changes.

— Reply to this email directly, view it on GitHub https://github.com/DanBloomberg/leptonica/issues/707#issuecomment-1822953395 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADG74NBRCZO4U3IP56UI3HDYFYIVDAVCNFSM6AAAAAA3S57AX6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRSHE2TGMZZGU . You are receiving this because you authored the thread. https://github.com/notifications/beacon/ADG74NHDX5G3NZ4A5YU3MC3YFYIVDA5CNFSM6AAAAAA3S57AX6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTMVAH3G.gif Message ID: @. @.> >

rajeshja commented 7 months ago

Once the dependency is compiled, the original code works. The above changes I have listed allow the code to be built with VS 2019.

DanBloomberg commented 7 months ago

@egorpugin @zdenop

This looks to me like a documentation/maintenance issue worth fixing, because it is claimed to affect users who are building with versions of VS before 2022.

zdenop commented 7 months ago

@DanBloomberg : this is sw issue. There is not problem to build leptonica with VS2019 (and cmake without sw [-DSW_BUILD=OFF])

DanBloomberg commented 7 months ago

Thanks. Is this documented, or if not, should it be?

zdenop commented 7 months ago

at least at https://github.com/DanBloomberg/leptonica/blob/master/.github/workflows/cmake-win64.yml ;-)

zdenop commented 7 months ago

I wrote some instructions to wiki ( https://github.com/DanBloomberg/leptonica/wiki) - feel free to improve it (especially grammar ;- ) )

DanBloomberg commented 7 months ago

Thank you! I have modified it slightly, suggesting that one should load png, lz, jpeg and tiff libraries. The other 3 image I/O libraries are not as important.

There are two other optional dependencies, which are not image I/O:

I am in the process of putting code that uses poppler programs pdftoppm and pdfimages into the library, in a new file renderpdf.c (not yet added). Right now, the code that uses them is only in several programs; e.g., cleanpdf, croppdf, compresspdf.

We should at some point include these two optional dependencies in the wiki. You can see the information about gnuplot in gplot.c and about poppler in prog/cleanpdf.c, line 122 ff.

zdenop commented 7 months ago

I was focusing on building the library. AFAIK Leptonica is not linked against Gnuplot, right?

DanBloomberg commented 7 months ago

Yes, you're right. gnuplot and the poppler programs are not dependencies of the library, and are not linked.

They're just programs that can be called, so best to leave them out of this BUILD wiki.

Medalha commented 7 months ago

I wrote some instructions to wiki ( https://github.com/DanBloomberg/leptonica/wiki) - feel free to improve it (especially grammar ;- ) )

This document refers to jbigkit, lzma, and zstd as dependencies, but there's no provision for those libraries in Leptonica's 'CMakeLists.txt' file. Is this on purpose or just an oversight?

Thank you for the outstanding work with Leptonica.

zdenop commented 7 months ago

Ups. I forgot to reorder sections in wiki correctly... jbigkit, lzma, and zstd are used by libtiff -, they are not used by leptonica directly...

Please be aware that libtiff (maybe also others) has more optional dependencies that I did not cover in this tutorial.

DanBloomberg commented 7 months ago

We enable tiff read/write with two compression formats IFF_TIFF_ZIP and IFF_TIFF_JPEG that require libraries external to tiff. So the jpeg library is a dependency of tiff and needs to be included. I believe all computers have the zip library, so that's not an issue.

DanBloomberg commented 5 months ago

@zdenop Is this issue resolved?

zdenop commented 5 months ago

IMO yes

Medalha commented 5 months ago

I never met the issue again. Than you.

From: Dan Bloomberg @. Sent: 21 de janeiro de 2024 08:29 To: DanBloomberg/leptonica @.> Cc: Medalha @.>; Author @.> Subject: Re: [DanBloomberg/leptonica] Build fails under Windows (Issue #707)

@zdenop https://github.com/zdenop Is this issue resolved?

— Reply to this email directly, view it on GitHub https://github.com/DanBloomberg/leptonica/issues/707#issuecomment-1902553479 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADG74NAMB4BNFLXEOHQPCITYPTGUZAVCNFSM6AAAAAA3S57AX6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBSGU2TGNBXHE . You are receiving this because you authored the thread. https://github.com/notifications/beacon/ADG74NGEI5GYWIXA4FQUNH3YPTGUZA5CNFSM6AAAAAA3S57AX6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTRM2UYO.gif Message ID: @. @.> >