简体   繁体   English

用Cmake和MinGW编译OpenCV 2.4.13

[英]Compiling OpenCV 2.4.13 with Cmake and MinGW

I got this problem when trying to compile opencv using Cmake and mingw. 我在尝试使用Cmake和mingw编译opencv时遇到了这个问题。

for Cmake: sourcecode is located in "C:\\CPP Libraries\\OpenCV-2.4.13\\opencv\\sources" where the binaries are goint to be build is in: "C:/CPP Libraries/OpenCV-2.4.13/opencv/build/x64/mingw" 对于Cmake:sourcecode位于“C:\\ CPP Libraries \\ OpenCV-2.4.13 \\ opencv \\ sources”中,其中二进制文件是要构建的goint:“C:/ CPP Libraries / OpenCV-2.4.13 / opencv /建立/ X64 / MinGW的”

I've already used Cmake to generate the makefile. 我已经用Cmake生成了makefile。

when i run the makefile: 当我运行makefile时:

C:\CPP Libraries\OpenCV-2.4.13\opencv\build\x64\mingw>mingw32-make

this is the output that I get after 31% 这是我在31%之后获得的输出

[ 31%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_w32.cpp.obj
C:\CPP Libraries\OpenCV-2.4.13\opencv\sources\modules\highgui\src\window_w32.cpp: In function 'int icvCreateTrackbar(const char*, const char*, int*, int, CvTrackbarCallback, CvTrackbarCallback2, void*)':
C:\CPP Libraries\OpenCV-2.4.13\opencv\sources\modules\highgui\src\window_w32.cpp:1853:81: error: 'BTNS_AUTOSIZE' was not declared in this scope
                                         WS_CHILD | CCS_TOP | TBSTYLE_WRAPABLE | BTNS_AUTOSIZE | BTNS_BUTTON,
                                                                                 ^
C:\CPP Libraries\OpenCV-2.4.13\opencv\sources\modules\highgui\src\window_w32.cpp:1853:97: error: 'BTNS_BUTTON' was not declared in this scope
                                         WS_CHILD | CCS_TOP | TBSTYLE_WRAPABLE | BTNS_AUTOSIZE | BTNS_BUTTON,
                                                                                                 ^
modules\highgui\CMakeFiles\opencv_highgui.dir\build.make:187: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_w32.cpp.obj' failed
mingw32-make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_w32.cpp.obj] Error 1
CMakeFiles\Makefile2:2203: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/all' failed
mingw32-make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

Does anyone knows a solution, because i have no clue about this one. 有没有人知道一个解决方案,因为我对这个没有任何线索。

//EDIT! //编辑!

After downloaded the version from the git repository and try to build it i got these other errors. 从git存储库下载版本并尝试构建它后,我得到了其他错误。 I already try to change #define _WIN32_IE 0x0300 to #define _WIN32_IE 0x0500 in "commctrl.h" in MinGW directory, but it didn't worl. 我已经尝试在MinGW目录的“commctrl.h”中将#define _WIN32_IE 0x0300更改为#define _WIN32_IE 0x0500,但它没有发挥作用。

C:\CPP Libraries\OpenCV-2.4.13\Git\opencv\build\x64\mingw>mingw32-make
[  2%] Built target zlib
[  6%] Built target libtiff
[ 11%] Built target libjpeg
[ 16%] Built target libwebp
[ 19%] Built target libjasper
[ 20%] Built target libpng
[ 26%] Built target IlmImf
[ 26%] Built target opencv_core_pch_dephelp
[ 26%] Built target pch_Generate_opencv_core
[ 26%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.obj
C:\CPP Libraries\OpenCV-2.4.13\Git\opencv\modules\core\src\parallel.cpp: In function 'int cv::getThreadNum()':
C:\CPP Libraries\OpenCV-2.4.13\Git\opencv\modules\core\src\parallel.cpp:474:45: error: 'pthread_self' was not declared in this scope
     return (int)(size_t)(void*)pthread_self(); // no zero-based indexing
                                             ^
modules\core\CMakeFiles\opencv_core.dir\build.make:990: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.obj' failed
mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.obj] Error 1
CMakeFiles\Makefile2:1473: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

The problem (according to Artur Wieczorek) is OS version set by MinGW by default. 问题(根据Artur Wieczorek)是MinGW默认设置的操作系统版本。 To cure it find "commctrl.h" in MinGW directory and something like 为了治愈它在MinGW目录中找到“commctrl.h”之类的东西

 #if 0
 #define _WIN32_IE   0x0300
 #endif

then change it to 然后改为

 #if 1
 #define _WIN32_IE   0x0500
 #endif

expanding Le Quyen's answer: 扩大Le Quyen的答案:

You don't need "the git version". 不需要 “git版本”。

The error: 'BTNS_AUTOSIZE' was not declared in this scope for 2.4.13 is worked around in http://code.opencv.org/issues/4087 : error: 'BTNS_AUTOSIZE' was not declared in this scope 2.4.13在http://code.opencv.org/issues/4087中解决

  1. open C:\\MingW\\include\\commctrl.h or equivalent. 打开C:\\MingW\\include\\commctrl.h或同等的。
  2. search /* define _WIN32_IE if you really want it */ /* define _WIN32_IE if you really want it */搜索/* define _WIN32_IE if you really want it */
  3. edit the text underneath so it looks like this: 编辑下面的文字,看起来像这样:

     #if 1 #define _WIN32_IE 0x0500 #endif 

credits to Artur Wieczoek and Vit Shiryaev for the hint. 归功于Artur Wieczoek和Vit Shiryaev的暗示。


Why unset? 为什么不设置? I don't know but the people giving you MingW are trying to make this clear on their wiki : 我不知道但是给你MingW的人们试图在他们的维基上清楚地说明这一点

You need to set defines _WIN32_WINDOWS, _WIN32_WINNT, WINVER and/or _WIN32_IE to the minimum platform you plan to support before including the windows.h header file. 在包含windows.h头文件之前,需要将_WIN32_WINDOWS,_WIN32_WINNT,WINVER和/或_WIN32_IE定义到您计划支持的最小平台。 Possible values for these definitions can be found in the header w32api.h file. 可以在头文件w32api.h中找到这些定义的可能值。

I am trying to compile OpenCV 3.1 with the nonfree modules for Android and I got the message 我正在尝试用Android的非自由模块编译OpenCV 3.1,我收到了消息

error: 'pthread_self' was not declared in this scope

It was solved by including "ANDROID_NDK_LAYOUT" with value "RELEASE". 它通过包含值为“RELEASE”的“ANDROID_NDK_LAYOUT”来解决。

My CMake configuration: CMake configuration 我的CMake配置: CMake配置

I made a "mingw32-make clean" (just in case) and "mingw32-make" 我做了一个“mingw32-make clean”(以防万一)和“mingw32-make”

I had the exact same issue so this question is actually valid and it makes me wonder why it got down-voted. 我有完全相同的问题所以这个问题实际上是有效的,它让我想知道为什么它被投票。

I am on windows10. 我在windows10上。 After many tries, I solved this by simply downloading openCV-3.1.0 instead of 2.4.13. 经过多次尝试,我通过简单地下载openCV-3.1.0而不是2.4.13解决了这个问题。

Prior to moving to openCV-3.1.0, I tried installing code::blocks alone then installing the latest mingw version. 在转向openCV-3.1.0之前,我尝试单独安装code :: blocks,然后安装最新的mingw版本。 Didn't help. 没有帮助。 I also tried generating the makefile using the 32 bit version of CMake vs the 64 bit version. 我也尝试使用32位版本的CMake和64位版本生成makefile。 Didn't help either. 也没有帮助。

With opencCV-3.1.0, you need not edit any .h files like I read elsewhere. 使用opencCV-3.1.0,您无需编辑任何.h文件,就像我在别处阅读一样。 Expect a longer mingw32-make execution time too. 期望更长的mingw32-make执行时间。

我通过在CMake中取消选中WITH_PTHREADS_PF解决了pthread_self错误

I was also getting something like 我也得到了类似的东西

"opencv/sources/module/core/src/parallel.cpp": In function "int cv::getThreadNum()" ......./parallel.cpp:505:45: error: 'pthread' was not declared in the scope “opencv / sources / module / core / src / parallel.cpp”:在函数“int cv :: getThreadNum()”....... / parallel.cpp:505:45:错误:'pthread'不是在范围内声明

I tried the above suggestion to change Mingw/include/commctrl.h as: 我尝试了上面的建议,将Mingw / include / commctrl.h更改为:

#ifndef _WIN32_IE
/* define _WIN32_IE if you really want it */
#if 0                           // to 1
#define _WIN32_IE   0x0300      // to 0x0500
#endif
#endif

but things didn't went ahead and I was still stuck with same problem. 事情没有继续下去,我仍然遇到同样的问题。

Then I unchecked the "WITH_PTHREADS_PF" in CMake-GUI flag list and proceeded. 然后我取消选中CMake-GUI标志列表中的“WITH_PTHREADS_PF”并继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM