install opencv 3.4.1 and Qt 5.10 with CMAKE

2019-03-01 02:06发布

问题:

I install Qt 5.10 latest version and opencv3.4.1 and I couldn't install the library in this version of Qt with Cmake can anybody help me to do it on my windows 10 64-bit please? I tried with this video also https://www.youtube.com/watch?v=ZOSu-2Oju-A and in cmd step I have this (picture in this link)

in this link also (( https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows )) I do all steps carefully but I didn't found the folder bin in opencv-build after do the steps and My OS is windows 10 64-bit thanks for help.

回答1:

Note: I'm basing my answer more on [SO]: openCV mingw-32 error in cmd (the tools versions mentioned in the posted .pdf)

1. Preliminary considerations

At the beginning, I tried to build it using what I already had on my machine (Win 10):

  • CMake 3.6.4 (bundled by Android Studio - that I didn't updated for months BTW), cmdline - as there's no GUI
  • MinGW7.2.0 (that I built on my machine for a different task)
    • g++ 7.2.0
  • OpenCV 3.4.2 (downloaded [GitHub]: opencv/opencv - opencv-3.4.2.zip, specifically for this task)


The build process passed this stage (well, it failed somewhere below this point, I didn't check why exactly). Anyway, I thought that the build env that I used, and the suggested one were too far away, so I:

  • Downloaded CMake 3.6.3 Win x64 bundle (that contains cmake-gui - as cmdline can be a pain, especially for those that are not used to it)
  • Used MinGW 5.3.0 (part of my Qt installation)
    • g++ 5.3.0

The problem at its core (as specified in comments, or Googleing the error) is that the g++ compiler doesn't use the C++11 standard (and protobuf source code requires it).
So, I did a little test: pasted the faulty code in a file (and added a dummy main), and tried it with the 2 MinGW installations.

code.py:

template <typename char_type>
bool null_or_empty(const char_type* s) {
    return s == nullptr || *s == 0;
}

int main() {
    return 0;
}

Output:

e:\Work\Dev\StackOverflow\q051629751>dir /b
build
build.bat
cmake-gui.exe - Shortcut.lnk
code.cpp
src

e:\Work\Dev\StackOverflow\q051629751>set _PATH=%PATH%

e:\Work\Dev\StackOverflow\q051629751>set PATH=%_PATH%;c:\Install\x64\MinGW32\MinGW32\7.2.0-posix-seh-rt_v5-rev1\mingw64\bin

e:\Work\Dev\StackOverflow\q051629751>"c:\Install\x64\MinGW32\MinGW32\7.2.0-posix-seh-rt_v5-rev1\mingw64\bin\g++" code.cpp

e:\Work\Dev\StackOverflow\q051629751>"c:\Install\x64\MinGW32\MinGW32\7.2.0-posix-seh-rt_v5-rev1\mingw64\bin\g++" --version
g++ (x86_64-posix-seh-rev1, Built by MinGW-W64 project) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


e:\Work\Dev\StackOverflow\q051629751>dir /b
a.exe
build
build.bat
cmake-gui.exe - Shortcut.lnk
code.cpp
src

e:\Work\Dev\StackOverflow\q051629751>del /q a.exe

e:\Work\Dev\StackOverflow\q051629751>set PATH=%_PATH%;c:\Install\Qt\Qt\Tools\mingw530_32\bin

e:\Work\Dev\StackOverflow\q051629751>"c:\Install\Qt\Qt\Tools\mingw530_32\bin\g++" code.cpp
code.cpp: In function 'bool null_or_empty(const char_type*)':
code.cpp:3:17: error: 'nullptr' was not declared in this scope
     return s == nullptr || *s == 0;
                 ^

e:\Work\Dev\StackOverflow\q051629751>"c:\Install\Qt\Qt\Tools\mingw530_32\bin\g++" --version
g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


e:\Work\Dev\StackOverflow\q051629751>"c:\Install\Qt\Qt\Tools\mingw530_32\bin\g++" code.cpp -std=c++0x

e:\Work\Dev\StackOverflow\q051629751>

As seen, the older g++ needs -std=c++0x explicitly.

Following the build steps, I got the same error as in the image below (I launched mingw32-make directly in protobuf's dir, to skip all the other stuff built before it):

2. Solutions

Both are done at cmake-gui level. After setting the paths:

  • Hit "Configure"
  • Do the required variable changes
  • Hit "Generate"
  • Launch mingw32-make from console, in the build dir

Notes:

  • Since I'm very far away from being a CMake expert, before doing this, I empty the build dir to make sure that there's nothing left from previous build (of course the drawback is that everything is done again, which usually takes a long time)

  • Since I didn't enable parallel build, I didn't wait for the full build to finish (as it takes forever), but just checked that it passes this point

2.1 Force C++11 standard

Click "Add Entry" and set [CMake 3.1]: CXX_STANDARD:

And below, notice that the build passed point where it was failing before:

2.2 Skip protobuf build

Notes:

  • In the posted movie, there's no protobuf build attempted (probably it's not in the bundle?) that's why this error didn't pop up
  • I don't know what functionality will not be available in the final build, as I don't know what protobuf is used at
  • I consider this more like a workaround

Search for protobuf related variables, and uncheck any that are in the BUILD or WITH groups (the blue lines):

And again the effect is below - the protobuf build no longer takes place (it comes just after libIlmImf):