Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-Compiling Leptonica for Windows on Arch Linux #749

Open
Danny4021 opened this issue Jun 27, 2024 · 9 comments
Open

Cross-Compiling Leptonica for Windows on Arch Linux #749

Danny4021 opened this issue Jun 27, 2024 · 9 comments

Comments

@Danny4021
Copy link

Hello,

as stated in the title, I'm currently trying to cross-compile a Windows DLL for Leptonica on my Arch Linux System (Since our software needs to run on Windows and Linux) and I can't really get it to work.
I was trying to find anything inside the documentation about cross-compiling but I've not been able to find anything about it.
Here are the steps I took:

  • clone the Leptonica Repository git clone https://github.com/DanBloomberg/leptonica.git
  • Run the autogen.sh ./autogen.sh
  • Configure the mingw compiler like this ./configure --host=x86_64-w64-mingw32 --prefix=/home/leptonica/build --disable-static
  • Run make

After running these steps I get the following error:

jpegio.c:144:10: fatal error: jpeglib.h: No such file or directory
  144 | #include "jpeglib.h"
      |          ^~~~~~~~~~~
compilation terminated.

But that's not the main issue, since I can circumvent it by copying the necessary header files into the leptonica/src folder on my system (For some reason this error only occurs when trying to cross-compile. It doesn't happen when I don't configure the host when running ./configure)

After copying all the header files it's missing I get the following error after re-running make

Making all in prog
make[2]: Entering directory '/home/leptonica/prog'
  CCLD     convertfilestopdf.exe
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lpng16: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -ljpeg: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -ltiff: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lwebp: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lwebpmux: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lopenjp2: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lz: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:2952: convertfilestopdf.exe] Error 1
make[2]: Leaving directory '/home/leptonica/prog'
make[1]: *** [Makefile:536: all-recursive] Error 1
make[1]: Leaving directory '/home/leptonica'
make: *** [Makefile:420: all] Error 2

Now to my questions:
Am I doing something fundamentally wrong?
Does anyone have recent experience cross-compiling leptonica for Windows or does someone have a tutorial on this matter? (I've been looking for a while but I haven't been able to find anything)
I'd just like to know if I'm on the right track or if I'm doing something very wrong.

Any kind of help on that matter would be much appreciated.
Thanks in advance!
Kind regards

(If this helps, here are the packages I've installed on arch in order to compile it):

mingw-w64-binutils 2.39-1
mingw-w64-crt 11.0.0-1
mingw-w64-environment 1-5
mingw-w64-gcc 13.1.0-1
mingw-w64-headers 11.0.0-1
mingw-w64-make 1-5
mingw-w64-winpthreads 11.0.0-1
libjpeg-turbo 3.0.2-2
libpng 1.6.43-1
libtiff 4.6.0-4
libtool 2.4.7+4+g1ec8fa28-7
lzlib 1.14-1
make 4.4.1-2
autoconf 2.72-1
automake 1.16.5-2
@DanBloomberg
Copy link
Owner

I have not had any experience building windows programs from unix.
The linker is not finding the image compression libraries.
Have you looked at section 3 (b),(c) of the README.html?

@Danny4021
Copy link
Author

Thank you very much for the quick response!

I've re-read the mentioned paragraphs of the article and checked the necessery dependencies in section I/O libraries leptonica is dependent on once more.

Sadly, I can't use MSYS2 or Cygwin for my purposes since both of them are for Windows-Only.
I've followed the steps in section 3 (b) and installed mingw32 but it refers back to section 2 if I want to build a DLL.
So I guess that both steps 3 (b) and 3 (c) are only applicable if you use MSYS or Cygwin on a Windows system, since following the steps of section 2 creates just the so files on Linux systems.

I've also re-confirmed that all the packages mentioned in section I/O libraries leptonica is dependent on are installed and inside the expected folder. (Since I don't want to use the static makefile I've confirmed that all the files are present in form of shared libraries)

Is there maybe a way to simulate a Windows environment on linux like what MSYS2 or Cygwin do for Windows?

Thanks in advance!

@DanBloomberg
Copy link
Owner

Sorry, I haven't used cross-compiling (mingw).
I will send an email to Dave Bryan in case he has a suggestion for you.

@DanBloomberg
Copy link
Owner

Although Dave Bryan hasn't used gnu on linux when running mingw,
he made this observation about cross-compilation:

The cross-compiler looks in alternate places for headers and libraries, rather than
in the "standard" places used by the native compiler.  These can be
determined by running the cross-compiler with something more-or-less like
this (where "x86_64-w64-mingw32-gcc" is a long-handed symbol for the
actual cross-compiler):

  x86_64-w64-mingw32-gcc -print-search-dirs

This should display the set of directories where gcc expects to find
libraries.

For headers, this should do it (again, more-or-less, as I've never used
cross-compilers):

  x86_64-w64-mingw32-cpp -v /dev/null

Placing the header and library files in some directories shown in the
search paths should resolve this issue. 

@stweil
Copy link
Collaborator

stweil commented Jun 30, 2024

@Danny4021, do you have x86_64-w64-mingw32-pkg-config in your search PATH? It is required and will automatically set the right compiler flags for the header files.

I use ../configure --host=x86_64-w64-mingw32 --prefix=/usr/x86_64-w64-mingw32 PKG_CONFIG_PATH=/mingw64/lib/pkgconfig on Debian GNU Linux. It prints somethink like this:

[...]
checking for x86_64-w64-mingw32-pkg-config... /usr/bin/x86_64-w64-mingw32-pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for zlib... yes
checking for libpng... yes
checking for libjpeg... yes
checking for DGifOpenFileHandle in -lgif... no
checking for gif_lib.h... no
checking for libtiff-4... yes
checking for libwebp... yes
checking for libwebpmux >= 0.5.0... yes
checking for libopenjp2 >= 2.0.0... yes
[...]

The directory /mingw64 contains the cross library packages which are installed with pacman on my build host.

@Danny4021
Copy link
Author

Hello @stweil,
thanks for the response!
No, I haven't the pkg-config in my search path. It doesn't seem like ths is installed by default when installing the mingw package for linux and is found inside another package (the mentioned /mingw64 also does not exist on my arch linux system).

I'm currently on vacation so I'll get back to you all next monday when I get to try your suggested solutions.
Thanks for the help!

@Danny4021
Copy link
Author

Hello again @stweil
for testing purposes, I've switched to a Linux Debian VM to see if I can make it work on there.
As suggested, I've run ./configure --host=x86_64-w64-mingw32 --prefix=/usr/x86_64-w64-mingw32 PKG_CONFIG_PATH=/usr/share/pkgconfig as my configure command.
I've copied all pc files needed by leptonica into the mentioned pkgconfig folder, which is the default folder used by the /usr/bin/x86_64-w64-mingw32-pkg-config file.
But the original problem still persists, even with this approach.

This is the output of my ./configure call:

checking for x86_64-w64-mingw32-pkg-config... /usr/bin/x86_64-w64-mingw32-pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for zlib... yes
checking for libpng... yes
checking for libjpeg... yes
checking for DGifOpenFileHandle in -lgif... no
checking for gif_lib.h... no
checking for libtiff-4... no
checking for TIFFOpen in -ltiff... no
checking for tiff.h... no
checking for libwebp... yes
checking for libwebpmux >= 0.5.0... yes
checking for libopenjp2 >= 2.0.0... yes

(I honestly don't know why it doesn't find libtiff-4 even though I've copied the pc file to the specified folder)

@DanBloomberg thanks for the help, I was able to find the lib folder thanks to the x86_64-w64-mingw32-gcc -print-search-dirs command.
This tells me the static libraries should be inside /usr/x86_64-w64-mingw32/lib
I've copied all .a files into the folder and most of the error message were resolved.
The only package that is still missing is lz:

make[2]: Entering directory '/home/danny/leptonica/prog'
  CCLD     convertfilestopdf.exe
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lz: No such file or directory
collect2: error: ld returned 1 exit status

Do you know if there's anything special about this library? I've copied the files of the library liblz-dev over into the specified folder.
Here my ls output:

/usr/x86_64-w64-mingw32/lib$ ls *lz*
liblz32.a  liblz.a  liblzma.a

This made me wonder: is this maybe the wrong library? Copying the .a files worked for every other missing library but not for this one. Do you perhaps know if there is a specific library which I have to install for it? (didn't find anything inside the readme)

Thanks for the help!

@stweil
Copy link
Collaborator

stweil commented Jul 8, 2024

As suggested, I've run ./configure --host=x86_64-w64-mingw32 --prefix=/usr/x86_64-w64-mingw32 PKG_CONFIG_PATH=/usr/share/pkgconfig as my configure command.

You'll need x86_64-w64-mingw32-pkg-config which is provided by the Debian package mingw-w64-tools.

@Danny4021
Copy link
Author

Thanks for the quick response!

I already have the x86_64-w64-mingw32-pkg-config.
mingw-64-tools installs this file under /usr/bin/x86_64-w64-mingw32-pkg-config.
I've looked inside the file to see what the "default" pkgconfig-path is and found that the default path is /usr/share/pkgconfig/.
So this is the path I've configured inside the ./configure script and also the path in which I've saved the necessary pc files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants