Closed blr21560 closed 4 years ago
I am not familiar with windows, could you try the Linux subsystem?
Yeah, I need help with Windows too
I'll give it a go and see what I can figure out this weekend.
Lept is the leptonica library http://www.leptonica.org/ https://github.com/DanBloomberg/leptonica
These instructions are a work in progress. They don't actually get this running, but I feel like I made progress towards it.
Please install:
Please run:
vcpkg install leptonica tesseract
Set your CPATH
for clang.
# Modify to be your vcpkg installation directory
set CPATH=C:\Users\ccouz\Documents\git\github.com\Microsoft\vcpkg\installed\x64-windows\include
⚠️ But this doesn't make it link.
Leptonica.lib
is installed at C:\Users\ccouz\Documents\git\github.com\Microsoft\vcpkg\installed\x64-windows\lib\leptonica-1.78.0.lib
on my computer. I can't work out what environment variable to set to make it pick this up. Renaming it to lept.lib
didn't seem to help.
It's not a very satisfactory thing to do, but by copying
tesseract.lib (renamed from tesseract41.lib)
lept.lib (renamed from leptonica-1.78.0.lib)
from C:\Users\ccouz\Documents\git\github.com\Microsoft\vcpkg\installed\x64-windows\lib
to the leptess directory, and with this minor patch
diff --git a/src/leptonica.rs b/src/leptonica.rs
index 1cea6eb7..0766ed88 100644
--- a/src/leptonica.rs
+++ b/src/leptonica.rs
@@ -103,7 +103,7 @@ impl Boxa {
unsafe { (*self.raw).n as usize }
}
- pub fn get_box(&self, i: usize, flag: u32) -> Option<Box> {
+ pub fn get_box(&self, i: usize, flag: i32) -> Option<Box> {
unsafe {
let b = capi::boxaGetBox(self.raw, i as i32, flag as i32);
if b.is_null() {
I was able to run cargo test
.
I'd like the input of someone more familiar with building on Windows, so that we can make it far more seamless.
Anyway it's kind of progress
I suspect the cause is that the 2 sys libraries used by leptess do not compile nicely on windows:
I'll try and update them with the suggestions from this article. Maybe next weekend. It might mean some big changes to them (submoduling and compiling leptonica and tesseract for example).
I'll try and update them with the suggestions from this article. Maybe next weekend. It might mean some big changes to them (submoduling and compiling leptonica and tesseract for example).
This is currently beyond me, but (as always) I'll accept patches.
I figured it out for msvc toolchain! I'm building using VS 2019 community edition.
set LIBCLANG_PATH=C:\'**your path to LLVM distro**'\bin
set INCLUDE=%INCLUDE%; '**your path**'\vcpkg\packages\leptonica_x64-windows\include
note, that vcpkg build x86 libs by default. If you need x64 libs (like in my case)
set VCPKG_DEFAULT_TRIPLET=x64-windows
before installing them using vcpkg
EDIT: forgot to add tesseract
set INCLUDE=%INCLUDE%;**your path**\vcpkg\packages\leptonica_x64-windows\include;**your path**\vcpkg\packages\tesseract_x64-windows\include
EDIT 2: Sorry, writing this late at night. forgot the most important part
set LIBPATH=%LIBPATH%;**your path**\vcpkg\packages\tesseract_x64-windows\lib\;**your path**\vcpkg\packages\leptonica_x64-windows\lib\
and make symbolic links in corresponding library directories
mklink lept.lib leptonica-1.78.0.lib
mklink tesseract.lib tesseract41.lib
I'll try to come up with fixes for both *-sys crates. I'm going to use vcpkg crate for this purpose and conditionally use it on win platforms
Thanks @rucoder for the update and @ccouzens for your work. Hope this leads into a usable workaround for Windows :). I'll try tonight these steps.
@rucoder What is LLVM ?
@rucoder What is LLVM ?
@DuckerMan it is a tool used to help building compilers. The Rust compiler uses it. It's also used by the compilers of many other languages. https://en.wikipedia.org/wiki/LLVM
The C compiler that uses LLVM is called Clang. I suspect Clang and LLVM are distributed together because C is a very important language.
I guess you're meant to download the Windows prebuilt binary from http://releases.llvm.org/download.html in order to follow @rucoder's instructions.
set LIBCLANG_PATH=C:\'your path to LLVM distro'\bin
I'll try to come up with fixes for both *-sys crates. I'm going to use vcpkg crate for this purpose and conditionally use it on win platforms
Thank you @rucoder
Ok, the fixes for both -sys crates are ready. This is my first time contributing to Rust libraries. Here is the question: I see that leptess depends on not the latest version of sys crates. Should I just create PRS for the latest versions and then owners will integrate them back to earlier versions or... that is the process?
Ok, the fixes for both -sys crates are ready. This is my first time contributing to Rust libraries. Here is the question: I see that leptess depends on not the latest version of sys crates. Should I just create PRS for the latest versions and then owners will integrate them back to earlier versions or... that is the process?
First submit PRs for both *-sys crates. Once those are merged and packaged, then any of us can update the dependencies of leptess.
Actually, I'm not sure we'll even have to update the dependencies of leptess, because they're flexible.
Leptess will currently try and install the newest version of leptonica-sys 0.3.x, and tesseract-sys 0.5.x.
I've submitted two PRs. Please note that following settings must be added to tasks.json in VS code if you use it
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"subcommand": "build",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
},
// These two environment variables MUST be defined for successfull build
// if you need staically linked libraries then set
// RUSTFLAGS=-Ctarget-feature=+crt-static instead of VCPKGRS_DYNAMIC
"options": {
"env": {
"LIBCLANG_PATH": "C:\\LLVM-OFF\\bin",
"VCPKGRS_DYNAMIC": "1"
}
}
}
]
}
From vcpkg documentation
Note: You must set one of RUSTFLAGS=-Ctarget-feature=+crt-static or VCPKGRS_DYNAMIC=1 in your environment or the vcpkg-rs helper will not find any libraries. If VCPKGRS_DYNAMIC is set, cargo install will generate dynamically linked binaries, in which case you will have to arrange for dlls from your Vcpkg installation to be available in your path.
https://docs.rs/vcpkg/0.2.8/vcpkg/
I think README files should be updated as well
Thanks to the excellent work @rucoder has done with tesseract-sys
and leptonica-sys
, I've been able to bring it all together and make a PR for running leptess
on Windows.
Feel free to try it out and leave feedback if required https://github.com/houqp/leptess/pull/11
As I can see the work is not finished. The package version should be bumped to 0.8.2 and it should be re-released on craits.io. It is not enough to just bump leptonia-sys and teserract-sys craits version in cargo.toml
Hi @rucoder , thanks for prompting me. I'll do that now.
Hi @rucoder , thanks for prompting me. I'll do that now.
I'll be glad o be a first tester for this :)
leptess = "0.8.2"
has been published. @rucoder let me know how you get on and thanks for your patience
I confirm that 0.8.2 builds and runs just fine on my PC. The issue can be closed I guess
Hi,
I can't link under Windows. The linker search lept.lib. Where can i find this library for windows ? Thanks,