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 install on Windows (syntax errors in common.hpp) #125

Closed
YoshiWalsh opened this issue May 5, 2020 · 38 comments
Closed

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

YoshiWalsh opened this issue May 5, 2020 · 38 comments

Comments

@YoshiWalsh
Copy link

YoshiWalsh commented May 5, 2020

  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

@twistedfall
Copy link
Owner

twistedfall commented May 6, 2020

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 };

@YoshiWalsh
Copy link
Author

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.

@twistedfall
Copy link
Owner

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

@YoshiWalsh
Copy link
Author

I have that enabled.

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

@twistedfall
Copy link
Owner

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.

@YoshiWalsh
Copy link
Author

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.

@twistedfall
Copy link
Owner

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.

@YoshiWalsh
Copy link
Author

YoshiWalsh commented May 7, 2020

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.

@twistedfall
Copy link
Owner

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

@YoshiWalsh
Copy link
Author

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
Copy link
Author

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

So fixing the environment variable didn't help.

@twistedfall
Copy link
Owner

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

@YoshiWalsh
Copy link
Author

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

@twistedfall
Copy link
Owner

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.

@YoshiWalsh
Copy link
Author

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.

@twistedfall
Copy link
Owner

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

@YoshiWalsh
Copy link
Author

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. :(

@twistedfall
Copy link
Owner

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.

@YoshiWalsh
Copy link
Author

YoshiWalsh commented May 9, 2020

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.

@twistedfall
Copy link
Owner

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!

@YoshiWalsh
Copy link
Author

@twistedfall
Copy link
Owner

twistedfall commented May 11, 2020

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
Copy link
Owner

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
Copy link
Owner

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

@YoshiWalsh
Copy link
Author

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.

@twistedfall
Copy link
Owner

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
Copy link
Owner

Were you able to follow up on that issue?

@YoshiWalsh
Copy link
Author

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.

@twistedfall
Copy link
Owner

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.

@YoshiWalsh
Copy link
Author

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

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

(Logs are too big for a single pastebin)

@twistedfall
Copy link
Owner

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

@YoshiWalsh
Copy link
Author

1

2

@twistedfall
Copy link
Owner

twistedfall commented Aug 6, 2020

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?

@ghmendonca
Copy link

ghmendonca commented Oct 14, 2020

@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"

@twistedfall
Copy link
Owner

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)?

@ghmendonca
Copy link

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
Copy link

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

@twistedfall
Copy link
Owner

It's great to hear that!

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

3 participants