opencv-rust icon indicating copy to clipboard operation
opencv-rust copied to clipboard

Cannot install on Windows (syntax errors in common.hpp)

Open YoshiWalsh opened this issue 5 years ago • 38 comments

  1. Operating system

Windows 10

  1. The way you installed OpenCV: package, official binary distribution, manual compilation, etc.
choco install llvm opencv

Then manually set

OPENCV_DIR=C:\tools\opencv\build\x64\vc14\lib
OPENCV_INCLUDE_PATHS=C:\tools\opencv\build\include
OPENCV_LINK_LIBS=opencv_world412
OPENCV_LINK_PATHS=C:\tools\opencv\build\x64\vc15\lib
OPENCV_PATH=C:\tools\opencv

Also installed Universal CRT SDK through Visual Studio Installer and manually set additional environment variables:

INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include;D:\Windows Kits\10\Include\10.0.17763.0\ucrt;D:\Windows Kits\10\Include\10.0.17763.0\um;
LIB=D:\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64;D:\Windows Kits\10\Lib\10.0.17763.0\um\x64
  1. OpenCV version

4.1.2 (Also see the exact same issue with the 4.2.0 release from the OpenCV website)

  1. Attach the full output of the following command from your project directory:
$env:RUST_BACKTRACE="full"; cargo build -vv 

https://pastebin.com/USHHvZbw

YoshiWalsh avatar May 05 '20 09:05 YoshiWalsh

That's quite weird, it looks like your version of cl.exe does not accept some code. As far as I can see the version used in CI works correctly.

Your compiler is:

C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\cl.exe

The working one in CI:

C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX64\\x64\\cl.exe

I'm not that familiar with the versioning of Visual Studio compilers, but it looks like it's 2019 vs 2017. So can you please update to 2019 first and then try again?

The code that it rejects is struct initializer:

return Result_void { .error_code = 0, .error_msg = 0 };

It's kind of weird that it's ok with the similar code that is a couple of lines above it:

return Result<T> { .error_code = 0, .error_msg = 0, .result = result };

twistedfall avatar May 06 '20 07:05 twistedfall

Thanks for your help. I uninstalled Visual Studio completely, since the folks at the vcpkg repo said that my non-default installation directory might have been causing issues. Then I installed Visual Studio 2019 and the required SDKs.

The syntax error issue seems to be gone, but now something else is going on.

YoshiWalsh avatar May 06 '20 13:05 YoshiWalsh

For Windows you pretty much have to enable buildtime-bindgen feature. It will almost never work without it.

twistedfall avatar May 06 '20 13:05 twistedfall

I have that enabled.

opencv = {version = "0.34", features = ["buildtime-bindgen"]}

YoshiWalsh avatar May 06 '20 21:05 YoshiWalsh

And you are still experiencing the same issue? Can you please post the full log then? The one you posted before has “cargo build -vv”, without features.

twistedfall avatar May 07 '20 04:05 twistedfall

opencv = {version = "0.34", features = ["buildtime-bindgen"]} is defined in my Cargo.toml file. It was definitely present at the time that I ran that cargo build -vv command.

YoshiWalsh avatar May 07 '20 04:05 YoshiWalsh

Ah, I see now, thanks. What I can see from the log is that there is a version mismatch between the link library opencv_world412 and version found in the headers: Found OpenCV library version: 4.2.0 in headers located at: C:\tools\opencv\build\include. The latest package version in choco is only 4.1.2. While this alone shouldn't produce errors during compilation stage (only during the link phase) it does indicate that there is something wrong with your OpenCV installation. I'd recommend uninstalling every instance of OpenCV you have on your computer, then deleting the leftover files by hand and then installing OpenCV from scratch.

twistedfall avatar May 07 '20 07:05 twistedfall

Ah, I did delete OpenCV and reinstall 4.2.0 from scratch, maybe I just need to update the OPENCV_LINK_LIBS environment variable? I'll try that when I get home.

YoshiWalsh avatar May 07 '20 07:05 YoshiWalsh

How did you install 4.2.0, by building it from the sources?

twistedfall avatar May 07 '20 08:05 twistedfall

There's an official Windows build of OpenCV 4.2.0 on the project's website: https://sourceforge.net/projects/opencvlibrary/files/4.2.0/opencv-4.2.0-vc14_vc15.exe/download

YoshiWalsh avatar May 07 '20 08:05 YoshiWalsh

New log: https://pastebin.com/UJikm05y

So fixing the environment variable didn't help.

YoshiWalsh avatar May 07 '20 08:05 YoshiWalsh

Can you please also tell me which version of clang/llvm have you installed? And how did you install it?

twistedfall avatar May 07 '20 09:05 twistedfall

I installed llvm via chocolatey and then forced a reinstall after I reinstalled VC++. choco install --force llvm. It's version 10.0.0.

YoshiWalsh avatar May 07 '20 09:05 YoshiWalsh

I wonder will it be possible for you to remove the 4.2.0 and install OpenCV from chocolatey just to rule out this part? Please also do a cargo clean before trying to build the project.

twistedfall avatar May 07 '20 09:05 twistedfall

Sure. I installed it from the OpenCV website because I was under the impression that 4.1.2 wasn't supported. (crates.io says only 3.2, 3.4, and 4.2 are supported) I'm installing from Choco now, I'll let you know how it goes.

YoshiWalsh avatar May 07 '20 09:05 YoshiWalsh

That's a documentation error, I'll update it, thanks!

twistedfall avatar May 07 '20 09:05 twistedfall

The log is now too long for pastebin. It starts with:

PS D:\git\video_inpaint> $env:OPENCV_LINK_LIBS
opencv_world412
PS D:\git\video_inpaint> cargo clean
PS D:\git\video_inpaint> $env:RUST_BACKTRACE='full'; cargo build -vv

and ends with https://pastebin.com/dP067hUW.

I had to omit some stuff in between, sorry.

Anyway, seems 4.1.2 behaves the same. :(

YoshiWalsh avatar May 07 '20 10:05 YoshiWalsh

Can you please try to change the path style to unix in your environment variables OPENCV_LINK_PATHS and OPENCV_INCLUDE_PATHS? So that they become

OPENCV_LINK_PATHS = /C/tools/opencv/build/x64/vc15/lib
OPENCV_INCLUDE_PATHS = /C/tools/opencv/build/include

or alternatively

OPENCV_LINK_PATHS = C:/tools/opencv/build/x64/vc15/lib
OPENCV_INCLUDE_PATHS = C:/tools/opencv/build/include

That's the only significant difference I can see between CI and your instance.

twistedfall avatar May 08 '20 14:05 twistedfall

With /C/tools/opencv/build/x64/vc15/lib it fails to find the library, it reports as version 0.0.0:

     Running `D:\git\video_inpaint\target\debug\build\opencv-3803a1430a370c12\build-script-build`
[opencv 0.34.0] === Environment configuration:
[opencv 0.34.0] ===   OPENCV_HEADER_DIR = None
[opencv 0.34.0] ===   OPENCV_PACKAGE_NAME = None
[opencv 0.34.0] ===   OPENCV_PKGCONFIG_NAME = None
[opencv 0.34.0] ===   OPENCV_LINK_LIBS = Some("opencv_world412")
[opencv 0.34.0] ===   OPENCV_LINK_PATHS = Some("/C/tools/opencv/build/x64/vc15/lib")
[opencv 0.34.0] ===   OPENCV_INCLUDE_PATHS = Some("/C/tools/opencv/build/include")
[opencv 0.34.0] ===   PKG_CONFIG_PATH = None
[opencv 0.34.0] ===   VCPKG_ROOT = None
[opencv 0.34.0] === Setting up OpenCV library from environment:
[opencv 0.34.0] ===   pkg_name: opencv4
[opencv 0.34.0] ===   link_libs: opencv_world412
[opencv 0.34.0] ===   link_paths: /C/tools/opencv/build/x64/vc15/lib
[opencv 0.34.0] ===   include_paths: /C/tools/opencv/build/include
[opencv 0.34.0] === OpenCV library configuration: Library {
[opencv 0.34.0]     pkg_name: "opencv4",
[opencv 0.34.0]     include_paths: [
[opencv 0.34.0]         "/C/tools/opencv/build/include",
[opencv 0.34.0]     ],
[opencv 0.34.0]     version: "0.0.0",
[opencv 0.34.0]     cargo_metadata: [
[opencv 0.34.0]         "cargo:rustc-link-search=/C/tools/opencv/build/x64/vc15/lib",
[opencv 0.34.0]         "cargo:rustc-link-lib=opencv_world412",
[opencv 0.34.0]     ],
[opencv 0.34.0] }
[opencv 0.34.0] Error: "OpenCV version: 0.0.0 must be from 4.x branch because of the feature: opencv-4, (version coming from the detected package/environment)"
error: failed to run custom build command for `opencv v0.34.0`

Caused by:
  process didn't exit successfully: `D:\git\video_inpaint\target\debug\build\opencv-3803a1430a370c12\build-script-build` (exit code: 1)
--- stderr
=== Environment configuration:
===   OPENCV_HEADER_DIR = None
===   OPENCV_PACKAGE_NAME = None
===   OPENCV_PKGCONFIG_NAME = None
===   OPENCV_LINK_LIBS = Some("opencv_world412")
===   OPENCV_LINK_PATHS = Some("/C/tools/opencv/build/x64/vc15/lib")
===   OPENCV_INCLUDE_PATHS = Some("/C/tools/opencv/build/include")
===   PKG_CONFIG_PATH = None
===   VCPKG_ROOT = None
=== Setting up OpenCV library from environment:
===   pkg_name: opencv4
===   link_libs: opencv_world412
===   link_paths: /C/tools/opencv/build/x64/vc15/lib
===   include_paths: /C/tools/opencv/build/include
=== OpenCV library configuration: Library {
    pkg_name: "opencv4",
    include_paths: [
        "/C/tools/opencv/build/include",
    ],
    version: "0.0.0",
    cargo_metadata: [
        "cargo:rustc-link-search=/C/tools/opencv/build/x64/vc15/lib",
        "cargo:rustc-link-lib=opencv_world412",
    ],
}
Error: "OpenCV version: 0.0.0 must be from 4.x branch because of the feature: opencv-4, (version coming from the detected package/environment)"

With C:/tools/opencv/build/x64/vc15/lib I seem to get the same error as before: https://pastebin.com/1EX5nCn5

Thanks for your help with this. It's very frustrating when I want to write some code but I'm prevented by toolchain issues, and I'm really grateful for you trying to figure it out for me.

YoshiWalsh avatar May 09 '20 08:05 YoshiWalsh

Well, then it would be nice if I could investigate what exactly it generated. Would you be able to do a cargo clean followed by the cargo build -vv? And note the output directory in the log (look for Generating code in: ...) and then share 3 directories:

  1. the output directory
  2. the bindings directory with the generated bindings (look for Placing generated bindings into: ... and strip the rust/opencv_4 part from the end of the path)
  3. your OpenCV headers (C:/tools/opencv/build/include).

Thanks!

twistedfall avatar May 09 '20 19:05 twistedfall

Here you go: http://randomshit.joshwalsh.me/opencvtroubleshooting.7z

YoshiWalsh avatar May 10 '20 01:05 YoshiWalsh

From the looks of it it seems that C++ standard library is completely missing for the binding generator. I'm starting to suspect llvm 10, can you please try replacing it with llvm 9.0.0 and trying again (cargo clean + cargo build)? In the meanwhile I'm doing the CI run with llvm 10 to see if I can reproduce that behavior.

twistedfall avatar May 11 '20 08:05 twistedfall

Nope, it's all good. Can you give me more details about the related installed software? As far as I understand you got llvm 10.0.0 and opencv 4.1.2 installed from choco. What about Visual Studio related packages? Can you provide me with the urls to the specific distributions and their versions that you have installed?

twistedfall avatar May 11 '20 09:05 twistedfall

And please also show me the output of the following commands:

clang --print-search-dirs

And this one, it's going to hang waiting for input so you'll need to Ctrl+C it:

clang -E -x c++ - -v

twistedfall avatar May 11 '20 09:05 twistedfall

Same symptoms with llvm 9.0.1.

For Visual Studio, I downloaded the latest (2019) Community edition from the official website. Installed .NET desktop development, Desktop development with C++ (including Windows 10 SDK), and Windows Universal CRT SDK.

> clang --print-search-dirs
programs: =C:\Program Files\LLVM\bin
libraries: =C:\Program Files\LLVM\lib\clang\9.0.1
> clang -E -x c++ - -v
clang version 9.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.25.28614 -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -momit-leaf-frame-pointer -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\9.0.1" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\9.0.1\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\include" -internal-isystem "D:\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt" -internal-isystem "D:\\Windows Kits\\10\\Include\\10.0.17763.0\\um" -fdeprecated-macro -fdebug-compilation-dir "C:\\WINDOWS\\system32" -ferror-limit 19 -fmessage-length 120 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.25.28614 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o - -x c++ -
clang -cc1 version 9.0.1 based upon LLVM 9.0.1 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include"
ignoring nonexistent directory "D:\Windows Kits\10\Include\10.0.17763.0\ucrt"
ignoring nonexistent directory "D:\Windows Kits\10\Include\10.0.17763.0\um"
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\9.0.1\include
End of search list.

My use case for OpenCV has passed, so there's no urgency any more. But I'm happy to keep testing things with you if you want to get to the bottom of it. At some point in future I might want to use OpenCV again and it would be nice if it worked.

YoshiWalsh avatar May 11 '20 11:05 YoshiWalsh

That's exactly it, this should list a bunch of Visual Studio header dirs:

#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\9.0.1\include
End of search list.

like

 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.24.28314\include
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt

And I can see that your clang is complaining about:

ignoring nonexistent directory "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include"

so it's somehow trying to reference the include directory from one of your old installations I suppose. Maybe some stale env var or not a clean uninstall of the old toolchain?

The first one is the directory that contains standard library definitions. Can you please try to find out which directory it is on your machine? I suppose it's something along the lines of C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include. When you find it can you please check whether it contains the file named vector?

twistedfall avatar May 11 '20 12:05 twistedfall

Were you able to follow up on that issue?

twistedfall avatar Jun 13 '20 16:06 twistedfall

Sorry for the delay. C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include does contain a file called vector, with no extension.

YoshiWalsh avatar Jun 14 '20 10:06 YoshiWalsh

Well, I'm not sure why exactly clang tries to use the wrong include directory, but can you try setting up the environment variable OPENCV_CLANG_STDLIB_PATH to "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/include" and try building? This should force-add that dir to the clang include path.

twistedfall avatar Jun 14 '20 13:06 twistedfall

Part 1: https://pastebin.com/ubDtqvVa

Part 2: https://pastebin.com/DA5ct39N

(Logs are too big for a single pastebin)

YoshiWalsh avatar Jun 14 '20 22:06 YoshiWalsh

Ah, sorry, I should have mentioned to use the latest version: 0.41.0. Will you please?

twistedfall avatar Jun 15 '20 04:06 twistedfall

1

2

YoshiWalsh avatar Jun 15 '20 11:06 YoshiWalsh

An issue has just been fixed in the crate version 0.44.2 which I think was also causing the problems with your build. Would you be able to retest?

twistedfall avatar Aug 06 '20 09:08 twistedfall

@twistedfall I have the same issue, but in my case it was missing the "stddef.h" file. I tried using the OPENCV_CLANG_STDLIB_PATH environment variable to my clang include folder and I get that the "limits" file is missing. I tried with clang 10 and 11 and both the same error. I tried using visual studio include folder and then I get that the "corecrt.h" file is missing..

I'm using windows 10 64bits and version 0.46 of this crate, so I still think the enviroment variable didn't fix this and somehow it's just not importing all standard libraries.

Here are the logs using clang 10: https://pastebin.com/YCP3Q6MX

And also, the limits.h file exists under the clang include folder

My Cargo.toml file:

[dependencies]
opencv = { version = "0.46", default-features = false, features = ["opencv-4", "buildtime-bindgen"] }

[lib]
name = "opencv"
crate-type = ["dylib"]

[build]
target = "x86_64-pc-windows-msvc"

ghmendonca avatar Oct 14 '20 03:10 ghmendonca

That's quite weird, clang should pick up you visual c++ include dirs, are you sure you have visual c++ build tools installed? Can you please also post the output of clang -E -x c++ - -v (please note that it will just hang there waiting for the output so just terminate it after it showed the initial wall of text)?

twistedfall avatar Oct 14 '20 07:10 twistedfall

Here are the logs from clang -E -x c++ - -v

clang version 10.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
 (in-process)
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\10.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\10.0.0\\include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 10.0/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 9.0/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 8/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include" -fdeprecated-macro -fdebug-compilation-dir "C:\\Program Files\\LLVM\\lib\\clang\\10.0.0\\include" -ferror-limit 19 -fmessage-length 120 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o - -x c++ -
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\10.0.0\include
End of search list.

So clang is looking for visual studio build tools in the wrong directory.. In my case it's installed in C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023

Is there any way of changing the directory to this one? Or I have to reinstall visual studio in the directory clang wants?

ghmendonca avatar Oct 14 '20 13:10 ghmendonca

I managed to get this working by reinstalling visual studio 2019 under C:/Program Files/Microsoft Visual Studio 9.0

ghmendonca avatar Oct 14 '20 14:10 ghmendonca

It's great to hear that!

twistedfall avatar Oct 14 '20 14:10 twistedfall