Tutorial for static builds on windows?
jonatino opened this issue · comments
Can't seem to find any guide for building staticically on windows.
@twistedfall left a message in that comment with a link to https://github.com/twistedfall/opencv-rust#static-build but it does not exist anymore unfortunately.
My current attempt uses the following env vars
[env]
LIBCLANG_PATH="C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\Llvm\\x64\\bin"
OPENCV_INCLUDE_PATHS="C:\\tools\\opencv\\build\\include"
OPENCV_HEADER_DIR="C:\\tools\\opencv\\build\\include"
OPENCV_LINK_PATHS="C:\\tools\\opencv\\build\\x64\\vc16\\lib"
OPENCV_LINK_LIBS="opencv_world4100.lib"
OPENCV_MSVC_CRT="static"
but it still looks for a dll on startup
Possible found the answer here: https://github.com/spoorn/media-to-ascii/blob/a01017fbb3dc883a89b0a1aff237c69b072542b2/.github/workflows/build.yml
Will reopen it if it does not work.
I've moved the installation guide into a separate file, so this is now the correct link: https://github.com/twistedfall/opencv-rust/blob/master/INSTALL.md#static-build
I haven't really tried building and linking statically on Windows myself, so if you have success please share and I'll link to your comment in the readme, thanks!
@twistedfall ended up getting it to work, using a mix of vcpkg and choco.
I used choco install llvm
I used https://github.com/mcgoo/cargo-vcpkg
Added the following to my Cargo.toml
file in the root of the project:
[package.metadata.vcpkg]
git = "https://github.com/microsoft/vcpkg"
rev = "94a50e8"
[package.metadata.vcpkg.target]
x86_64-pc-windows-msvc = { triplet = "x64-windows-static-release", dependencies = ["opencv4[contrib,nonfree]"] }
Then create a cargo config file in project_root/.cargo/config.toml
and add the following.
[env]
OPENCV_INCLUDE_PATHS= { value = "target\\vcpkg\\installed\\x64-windows-static-release\\include", relative = true }
OPENCV_LINK_PATHS= { value = "target\\vcpkg\\installed\\x64-windows-static-release\\lib", relative = true }
OPENCV_LINK_LIBS="opencv_core4.lib,opencv_imgproc4.lib,zlib.lib"
OPENCV_MSVC_CRT="static"
Then run cargo vcpkg -v build
.
Once that completes you'll be able to use cargo as normal. Eg cargo build
, cargo build --release
etc.
opencv4[contrib,nonfree]
@twistedfall ended up getting it to work, using a mix of vcpkg and choco.
I used
choco install llvm
I used https://github.com/mcgoo/cargo-vcpkg
Added the following to my
Cargo.toml
file in the root of the project:[package.metadata.vcpkg] git = "https://github.com/microsoft/vcpkg" rev = "94a50e8" [package.metadata.vcpkg.target] x86_64-pc-windows-msvc = { triplet = "x64-windows-static-release", dependencies = ["opencv4[contrib,nonfree]"] }
Then create a cargo config file in
project_root/.cargo/config.toml
and add the following.[env] OPENCV_INCLUDE_PATHS= { value = "target\\vcpkg\\installed\\x64-windows-static-release\\include", relative = true } OPENCV_LINK_PATHS= { value = "target\\vcpkg\\installed\\x64-windows-static-release\\lib", relative = true } OPENCV_LINK_LIBS="opencv_core4.lib,opencv_imgproc4.lib,zlib.lib" OPENCV_MSVC_CRT="static"
Then run
cargo vcpkg -v build
.Once that completes you'll be able to use cargo as normal. Eg
cargo build
,cargo build --release
etc.
Hello, cargo vcpk -v build
success,but i add
[dependencies]
opencv="*"
show below error
=== OpenCV library configuration: Library {
include_paths: [
"D:\\projects\\rust\\opencv4\\target\\vcpkg\\installed\\x64-windows-static-release\\include",
],
version: Version {
major: 0,
minor: 0,
patch: 0,
},
cargo_metadata: [
"cargo:rustc-link-search=D:\\projects\\rust\\opencv4\\target\\vcpkg\\installed\\x64-windows-static-release\\lib",
"cargo:rustc-link-lib=opencv_core4",
"cargo:rustc-link-lib=opencv_imgproc4",
"cargo:rustc-link-lib=zlib",
],
}
thread 'main' panicked at D:\software\cargo\registry\src\rsproxy.cn-8f6827c7555bfaf8\opencv-0.89.0\build.rs:346:9:
Unsupported OpenCV version: 0.0.0, must be from 3.2, 3.4 or 4.x branch