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

Cannot compile on Windows (again) #326

Closed
fzyzcjy opened this issue Mar 5, 2022 · 10 comments
Closed

Cannot compile on Windows (again) #326

fzyzcjy opened this issue Mar 5, 2022 · 10 comments

Comments

@fzyzcjy
Copy link
Contributor

fzyzcjy commented Mar 5, 2022

Hi thanks for the lib! I have checked the README and links in it but still fail.

Before reporting an issue please first check the
troubleshooting guide. If
the issue you're encountering is not solved thereby please state the following in your bugreport:

  1. Operating system: win10
  2. The way you installed OpenCV: package, official binary distribution, manual compilation, etc. choco install opencv
  3. OpenCV version: 4.5.5
  4. rustc version (rustc --version): rustc 1.55.0 (c8dfcfe04 2021-09-06)
  5. Attach the full output of the following command from your project directory:
    RUST_BACKTRACE=full cargo build -vv 

Reproduction:

cargo new ocvexpr
cd ocvexpr
vim Cargo.toml # and add 'opencv = "0.63.0"' into it
cargo build # then error

More info I can think of:

  • installed visual studio 2022 version 17.1, with “Desktop development with C++” workload selected (i.e. followed this page https://docs.flutter.dev/desktop to install things)

Some folder looks like:

image
image

For more logs: Run in a powershell, I get:

PS C:\Users\Tom\temp\ocvexpr> $env:OPENCV_LINK_PATHS="C:\tools\opencv\build\x64\vc15\lib"; $env:OPENCV_LINK_LIBS="opencv_world455"; $env:OPENCV_INCLUDE_PATHS="C:\tools\opencv\build\include"; $env:RUST_BACKTRACE="full"; $env:PATH += ';C:\tools\opencv\build\x64\vc15\bin'; cargo clean -p opencv; cargo build -vvv
       Fresh glob v0.3.0
       Fresh regex-syntax v0.6.25
       Fresh autocfg v1.1.0
       Fresh percent-encoding v2.1.0
       Fresh dunce v1.0.2
       Fresh jobserver v0.1.24
       Fresh once_cell v1.10.0
       Fresh maplit v1.0.2
       Fresh shlex v1.1.0
       Fresh pkg-config v0.3.24
       Fresh vcpkg v0.2.15
       Fresh cc v1.0.73
       Fresh memchr v2.4.1
       Fresh libc v0.2.119
       Fresh semver v1.0.6
       Fresh clang-sys v1.3.1
       Fresh aho-corasick v0.7.18
       Fresh num-traits v0.2.14
       Fresh clang v1.0.3
       Fresh regex v1.5.4
   Compiling opencv-binding-generator v0.41.0
     Running `set CARGO=\\?\C:\Users\Tom\.rustup\toolchains\1.55.0-x86_64-pc-windows-msvc\bin\cargo.exe&& set CARGO_CRATE_NAME=opencv_binding_generator&& set CARGO_MANIFEST_DIR=C:\Users\Tom\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\opencv-binding-generator-0.41.0&& set CARGO_PKG_AUTHORS="Pro <twisted.fall@gmail.com>"&& set CARGO_PKG_DESCRIPTION="Binding generator for opencv crate"&& set CARGO_PKG_HOMEPAGE=""&& set CARGO_PKG_LICENSE=MIT&& set CARGO_PKG_LICENSE_FILE=""&& set CARGO_PKG_NAME=opencv-binding-generator&& set CARGO_PKG_REPOSITORY=https://github.com/twistedfall/opencv-rust&& set CARGO_PKG_VERSION=0.41.0&& set CARGO_PKG_VERSION_MAJOR=0&& set CARGO_PKG_VERSION_MINOR=41&& set CARGO_PKG_VERSION_PATCH=0&& set CARGO_PKG_VERSION_PRE=""&& set PATH="C:\Users\Tom\temp\ocvexpr\target\debug\deps;C:\Users\Tom\.rustup\toolchains\1.55.0-x86_64-pc-windows-msvc\bin;C:\Users\Tom\.cargo\bin;C:\Users\Tom\.rustup\toolchains\1.55.0-x86_64-pc-windows-msvc\bin;C:\tools\ruby26\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Users\Tom\.cargo\bin;C:\Users\Tom\AppData\Local\Microsoft\WindowsApps;C:\tools\dart-sdk\bin;C:\Users\Tom\AppData\Roaming\Pub\Cache\bin;C:\Users\Tom\fvm\default\bin;C:\opencv\build\x64\vc15\bin;C:\tools\opencv\build\x64\vc15\bin"&& rustc --crate-name opencv_binding_generator --edition=2018 C:\Users\Tom\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\opencv-binding-generator-0.41.0\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=16286e9d240f1f40 -C extra-filename=-16286e9d240f1f40 --out-dir C:\Users\Tom\temp\ocvexpr\target\debug\deps -L dependency=C:\Users\Tom\temp\ocvexpr\target\debug\deps --extern clang=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libclang-2c00d41ab0b860e8.rmeta --extern clang_sys=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libclang_sys-a44b768539713b17.rmeta --extern dunce=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libdunce-acffe99432e44066.rmeta --extern maplit=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libmaplit-1045fc38a0e027b4.rmeta --extern once_cell=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libonce_cell-231c57d7a48bbb5c.rmeta --extern percent_encoding=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libpercent_encoding-ff57e3026375fa5f.rmeta --extern regex=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libregex-7b2023b03a578977.rmeta --cap-lints warn -L "C:\Program Files\LLVM\bin" -L "C:\Program Files\LLVM\lib"`
   Compiling opencv v0.63.0
     Running `set CARGO=\\?\C:\Users\Tom\.rustup\toolchains\1.55.0-x86_64-pc-windows-msvc\bin\cargo.exe&& set CARGO_CRATE_NAME=build_script_build&& set CARGO_MANIFEST_DIR=C:\Users\Tom\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\opencv-0.63.0&& set CARGO_PKG_AUTHORS="Pro <twisted.fall@gmail.com>:Mathieu Poumeyrol <kali@zoy.org>"&& set CARGO_PKG_DESCRIPTION="Rust bindings for OpenCV"&& set CARGO_PKG_HOMEPAGE=""&& set CARGO_PKG_LICENSE=MIT&& set CARGO_PKG_LICENSE_FILE=""&& set CARGO_PKG_NAME=opencv&& set CARGO_PKG_REPOSITORY=https://github.com/twistedfall/opencv-rust&& set CARGO_PKG_VERSION=0.63.0&& set CARGO_PKG_VERSION_MAJOR=0&& set CARGO_PKG_VERSION_MINOR=63&& set CARGO_PKG_VERSION_PATCH=0&& set CARGO_PKG_VERSION_PRE=""&& set PATH="C:\Users\Tom\temp\ocvexpr\target\debug\deps;C:\Users\Tom\.rustup\toolchains\1.55.0-x86_64-pc-windows-msvc\bin;C:\Users\Tom\.cargo\bin;C:\Users\Tom\.rustup\toolchains\1.55.0-x86_64-pc-windows-msvc\bin;C:\tools\ruby26\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Users\Tom\.cargo\bin;C:\Users\Tom\AppData\Local\Microsoft\WindowsApps;C:\tools\dart-sdk\bin;C:\Users\Tom\AppData\Roaming\Pub\Cache\bin;C:\Users\Tom\fvm\default\bin;C:\opencv\build\x64\vc15\bin;C:\tools\opencv\build\x64\vc15\bin"&& rustc --crate-name build_script_build --edition=2018 C:\Users\Tom\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\opencv-0.63.0\build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --cfg "feature=\"alphamat\"" --cfg "feature=\"aruco\"" --cfg "feature=\"barcode\"" --cfg "feature=\"bgsegm\"" --cfg "feature=\"bioinspired\"" --cfg "feature=\"calib3d\"" --cfg "feature=\"ccalib\"" --cfg "feature=\"cudaarithm\"" --cfg "feature=\"cudabgsegm\"" --cfg "feature=\"cudacodec\"" --cfg "feature=\"cudafeatures2d\"" --cfg "feature=\"cudafilters\"" --cfg "feature=\"cudaimgproc\"" --cfg "feature=\"cudaobjdetect\"" --cfg "feature=\"cudaoptflow\"" --cfg "feature=\"cudastereo\"" --cfg "feature=\"cudawarping\"" --cfg "feature=\"cvv\"" --cfg "feature=\"default\"" --cfg "feature=\"dnn\"" --cfg "feature=\"dnn_superres\"" --cfg "feature=\"dpm\"" --cfg "feature=\"face\"" --cfg "feature=\"features2d\"" --cfg "feature=\"flann\"" --cfg "feature=\"freetype\"" --cfg "feature=\"fuzzy\"" --cfg "feature=\"gapi\"" --cfg "feature=\"hdf\"" --cfg "feature=\"hfs\"" --cfg "feature=\"highgui\"" --cfg "feature=\"img_hash\"" --cfg "feature=\"imgcodecs\"" --cfg "feature=\"imgproc\"" --cfg "feature=\"intensity_transform\"" --cfg "feature=\"line_descriptor\"" --cfg "feature=\"mcc\"" --cfg "feature=\"ml\"" --cfg "feature=\"objdetect\"" --cfg "feature=\"optflow\"" --cfg "feature=\"ovis\"" --cfg "feature=\"phase_unwrapping\"" --cfg "feature=\"photo\"" --cfg "feature=\"plot\"" --cfg "feature=\"quality\"" --cfg "feature=\"rapid\"" --cfg "feature=\"rgbd\"" --cfg "feature=\"saliency\"" --cfg "feature=\"sfm\"" --cfg "feature=\"shape\"" --cfg "feature=\"stereo\"" --cfg "feature=\"stitching\"" --cfg "feature=\"structured_light\"" --cfg "feature=\"superres\"" --cfg "feature=\"surface_matching\"" --cfg "feature=\"text\"" --cfg "feature=\"tracking\"" --cfg "feature=\"video\"" --cfg "feature=\"videoio\"" --cfg "feature=\"videostab\"" --cfg "feature=\"viz\"" --cfg "feature=\"wechat_qrcode\"" --cfg "feature=\"xfeatures2d\"" --cfg "feature=\"ximgproc\"" --cfg "feature=\"xobjdetect\"" --cfg "feature=\"xphoto\"" -C metadata=9245e9e3437036dd -C extra-filename=-9245e9e3437036dd --out-dir C:\Users\Tom\temp\ocvexpr\target\debug\build\opencv-9245e9e3437036dd -L dependency=C:\Users\Tom\temp\ocvexpr\target\debug\deps --extern cc=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libcc-fa073c120022c18e.rlib --extern clang=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libclang-2c00d41ab0b860e8.rlib --extern dunce=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libdunce-acffe99432e44066.rlib --extern glob=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libglob-c00ed3851630a2da.rlib --extern jobserver=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libjobserver-0e9094054aec91d1.rlib --extern once_cell=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libonce_cell-231c57d7a48bbb5c.rlib --extern binding_generator=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libopencv_binding_generator-16286e9d240f1f40.rlib --extern pkg_config=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libpkg_config-7144d60a531ae6a4.rlib --extern semver=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libsemver-3d2865da17646360.rlib --extern shlex=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libshlex-410f35d3fd4692ce.rlib --extern vcpkg=C:\Users\Tom\temp\ocvexpr\target\debug\deps\libvcpkg-4178c11b7d256033.rlib --cap-lints warn -L "C:\Program Files\LLVM\bin" -L "C:\Program Files\LLVM\lib"`
     Running `C:\Users\Tom\temp\ocvexpr\target\debug\build\opencv-9245e9e3437036dd\build-script-build`
error: failed to run custom build command for `opencv v0.63.0`

Caused by:
  process didn't exit successfully: `C:\Users\Tom\temp\ocvexpr\target\debug\build\opencv-9245e9e3437036dd\build-script-build` (exit code: 0xc0000135, STATUS_DLL_NOT_FOUND)
@twistedfall
Copy link
Owner

twistedfall commented Mar 5, 2022

Did you check https://github.com/twistedfall/opencv-rust#troubleshooting, item 4?

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Mar 5, 2022

@twistedfall Thanks for the reply!

question edited. Now I have a $env:PATH += ';C:\tools\opencv\build\x64\vc15\bin' and I guess that should work

P.S. That folder does contain dll files, e.g.

PS C:\Users\Tom\temp\ocvexpr> ls C:\tools\opencv\build\x64\vc15\bin


    Directory: C:\tools\opencv\build\x64\vc15\bin


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        12/25/2021   1:01 PM          45568 opencv_annotation.exe
-a----        12/25/2021   1:01 PM         122880 opencv_interactive-calibration.exe
-a----        12/25/2021   1:01 PM          20480 opencv_model_diagnostics.exe
-a----        12/25/2021   1:01 PM          36864 opencv_version.exe
-a----        12/25/2021   1:01 PM          34304 opencv_version_win32.exe
-a----        12/25/2021  12:33 PM       20887552 opencv_videoio_ffmpeg455_64.dll
-a----        12/25/2021   1:01 PM         202752 opencv_videoio_msmf455_64.dll
-a----        12/25/2021  12:44 PM         743424 opencv_videoio_msmf455_64d.dll
-a----        12/25/2021   1:01 PM          59392 opencv_visualisation.exe
-a----        12/25/2021   1:01 PM       63742464 opencv_world455.dll
-a----        12/25/2021   1:01 PM       36843520 opencv_world455.pdb
-a----        12/25/2021  12:44 PM      128296960 opencv_world455d.dll
-a----        12/25/2021  12:44 PM      261877760 opencv_world455d.pdb

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Mar 5, 2022

Even tried this command: $env:OPENCV_LINK_PATHS="C:\tools\opencv\build\x64\vc15\lib"; $env:OPENCV_LINK_LIBS="opencv_world455"; $env:OPENCV_INCLUDE_PATHS="C:\tools\opencv\build\include"; $env:RUST_BACKTRACE="full"; $env:PATH += ';/C/tools/opencv/build/x64/vc15/bin'; cargo clean -p opencv; cargo build -vvv

where path is specified in unix style, which is mentioned in README like:

PATH Windows searches for *.dlls in PATH among other places, be sure to set it up, or copy required OpenCV *.dlls next to your binary. Be sure to specify paths in UNIX style (/C/Program Files/Dir) because colon in PATH might be interpreted as the entry separator. Summary here.

@twistedfall
Copy link
Owner

I'd still need the debug dump of the build as produced by RUST_BACKTRACE=full cargo build -vv, please also run cargo clean beforehand.

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Mar 5, 2022

I found the solution: Directly download from https://github.com/opencv/opencv/releases/tag/4.5.5

Wait a minute, I will write down

@twistedfall
Copy link
Owner

Btw for the bug above, seems that it errors even before opencv-rust can generate log (very strange)

Then it's probably related to inability to load clang dll

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Mar 5, 2022

After more experiments I see the problem: cargo clean -p opencv is not sufficient. Really need a cargo clean. With cargo clean, running the following command

$env:OPENCV_LINK_PATHS="C:\tools\opencv\build\x64\vc15\lib"; $env:OPENCV_LINK_LIBS="opencv_world455"; $env:OPENCV_INCLUDE_PATHS="C:\tools\opencv\build\include"; $env:RUST_BACKTRACE="full"; $env:PATH += ';/C/tools/opencv/build/x64/vc15/bin'; cargo clean; cargo build -vv

suffices to compile happily without errors.

Thanks for your suggestions!

(one comment above is deleted since later I found it wrong)

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Mar 5, 2022

For people in the future facing similar problems, here are my setup that works:

  1. No need to choco install opencv or do any global installation
  2. Instead, go to https://github.com/opencv/opencv/releases/tag/4.5.5 and download the opencv-4.5.5-openvino-dldt-2021.4.2-vc16-avx2.zip, and extract to somewhere (opencv_base_dir in the following code)
  3. Do something like what the following python script does. (Though the script uses some internal utility, it should be readable without knowing the internal utilities)
        opencv_base_dir = vision_utils_dir / \
                          'vision_utils_flutter_wrapper/windows/opencv-4.5.5-openvino-dldt-2021.4.2-vc16-avx2'

        opencv_link_paths = opencv_base_dir / 'build/lib'
        opencv_include_paths = opencv_base_dir / 'build/include'
        assert opencv_link_paths.exists() and opencv_include_paths.exists(), \
            f'Please manually download and put opencv for windows files into {opencv_base_dir}'
        opencv_envs = {
            'OPENCV_LINK_PATHS': str(opencv_link_paths),
            'OPENCV_LINK_LIBS': 'opencv_imgcodecs455,opencv_imgproc455,opencv_core455',
            'OPENCV_INCLUDE_PATHS': str(opencv_include_paths),
        }
        logger_main.message(f'opencv_envs={" ".join(f"{k}={v}" for k, v in opencv_envs.items())}')

        for k, v in opencv_envs.items():
            os.environ[k] = v

        run_command([
            'cargo', 'build',
            *profile.cargo_extra_flags,
            '--lib',
            '-vv'
        ], cwd=rust_base_dir)

@AdrianDosch
Copy link

For anyone still getting the error exit code: 0xc0000135, STATUS_DLL_NOT_FOUND after doing everything mentioned above, you also have to add clang to the PATH variable. For me it was C:\Program Files\LLVM\bin.
Usually this should happen automatically during the installation of LLVM, but didn't in my case.

@SquishyPon3
Copy link

For anyone still getting the error exit code: 0xc0000135, STATUS_DLL_NOT_FOUND after doing everything mentioned above, you also have to add clang to the PATH variable. For me it was C:\Program Files\LLVM\bin. Usually this should happen automatically during the installation of LLVM, but didn't in my case.

Thank you so much! I've got this setup working once before and was trying to get it set up on another machine and was absolutely falling apart unsure of why the DDLs were not getting found since I had not run into this issue previously. You saved me from so much trouble! You have no idea the sheer number of places I attempted to put the necessary env variables only for it to turn out LLVM was missing from path.

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

4 participants