Unable to use OpenCV on windows os

Hi,

I'm trying to use a opencv example. And have installed opencv using vcpkg on my windows laptop. But while compiling, it gives error:

C:\RustExercises\OpenCV>cargo build -vv
Fresh autocfg v1.0.1
Fresh cfg-if v1.0.0
Fresh lazy_static v1.4.0
Fresh adler32 v1.2.0
Fresh scopeguard v1.1.0
Fresh glob v0.3.0
Fresh byteorder v1.4.3
Fresh either v1.6.1
Fresh pkg-config v0.3.20
Fresh color_quant v1.1.0
Fresh regex-syntax v0.6.25
Fresh winapi-build v0.1.1
Fresh bitflags v1.3.2
Fresh gcc v0.3.55
Fresh jobserver v0.1.24
Fresh once_cell v1.8.0
Fresh maplit v1.0.2
Fresh percent-encoding v2.1.0
Fresh dunce v1.0.2
Fresh lzw v0.10.0
Fresh vcpkg v0.2.15
Fresh scoped_threadpool v0.1.9
Fresh weezl v0.1.5
Fresh winapi v0.2.8
Fresh adler v1.0.2
Fresh shlex v1.1.0
Fresh lazy_static v0.2.11
Fresh bytemuck v1.7.2
Fresh inflate v0.3.4
Fresh miniz_oxide v0.3.7
Fresh deflate v0.7.20
Fresh deflate v0.8.6
Fresh cc v1.0.71
Fresh gif v0.9.2
Fresh gif v0.11.3
Fresh libc v0.2.103
Fresh crossbeam-utils v0.8.5
Compiling clang-sys v1.2.2
Fresh memchr v2.4.1
Running C:\RustExercises\OpenCV\target\debug\build\clang-sys-dec2f9e1db421b78\build-script-build
Fresh semver v1.0.4
Fresh crc32fast v1.2.1
Fresh num-traits v0.2.14
Fresh memoffset v0.6.4
Fresh miniz_oxide v0.4.4
Fresh num_cpus v1.13.0
Fresh crossbeam-channel v0.5.1
Fresh aho-corasick v0.7.18
Fresh kernel32-sys v0.2.2
Fresh png v0.16.8
Fresh crossbeam-epoch v0.9.5
Fresh num-integer v0.1.44
Fresh num-traits v0.1.43
Fresh regex v1.5.4
Fresh escapi v3.0.5
Fresh crossbeam-deque v0.8.1
Fresh num-iter v0.1.42
Fresh enum_primitive v0.1.1
Fresh num-rational v0.1.42
[clang-sys 1.2.2] thread 'main' panicked at 'called Result::unwrap() on an Err value: "couldn't find any valid shared libraries matching: ['clang.dll', 'libcla
ng.dll'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (invalid: )"', C:\Users\Anjali.cargo\registry\src\github.
com-1ecc6299db9ec823\clang-sys-1.2.2\build\dynamic.rs:211:45
[clang-sys 1.2.2] note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
[clang-sys 1.2.2] cargo:warning=could not execute llvm-config one or more times, if the LLVM_CONFIG_PATH environment variable is set to a full path to valid llv m-config executable it will be used to try to find an instance of libclang on your system: "couldn't execute llvm-config --prefix (error: The system cannot fi
nd the file specified. (os error 2))"
Fresh num-rational v0.3.2
Fresh rayon-core v1.9.1
Fresh png v0.11.0
The following warnings were emitted during compilation:

warning: could not execute llvm-config one or more times, if the LLVM_CONFIG_PATH environment variable is set to a full path to valid llvm-config executable it
will be used to try to find an instance of libclang on your system: "couldn't execute llvm-config --prefix (error: The system cannot find the file specified.
(os error 2))"

error: failed to run custom build command for clang-sys v1.2.2

Caused by:
process didn't exit successfully: C:\RustExercises\OpenCV\target\debug\build\clang-sys-dec2f9e1db421b78\build-script-build (exit code: 101)

--- stdout
cargo:warning=could not execute llvm-config one or more times, if the LLVM_CONFIG_PATH environment variable is set to a full path to valid llvm-config execut
able it will be used to try to find an instance of libclang on your system: "couldn't execute llvm-config --prefix (error: The system cannot find the file spec
ified. (os error 2))"

--- stderr
thread 'main' panicked at 'called Result::unwrap() on an Err value: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set th
e LIBCLANG_PATH environment variable to a path where one of these files can be found (invalid: )"', C:\Users\Anjali.cargo\registry\src\github.com-1ecc6299db9e
c823\clang-sys-1.2.2\build\dynamic.rs:211:45
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

cargo.toml
[dependencies]
opencv = "0.55.0"
camera_capture = "0.5.0"
image = "0.23.14"

Please help.

Try following the instructions at Requirements - The `bindgen` User Guide to install libclang. It is needed by rust-bindgen, which the opencv crate seems to use to creating rust bindings to opencv.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.