简体   繁体   中英

Compiling OpenCV 2.4.13 with Cmake and MinGW

I got this problem when trying to compile opencv using Cmake and mingw.

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"

I've already used Cmake to generate the makefile.

when i run the makefile:

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

this is the output that I get after 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. 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.

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. To cure it find "commctrl.h" in MinGW directory and something like

 #if 0
 #define _WIN32_IE   0x0300
 #endif

then change it to

 #if 1
 #define _WIN32_IE   0x0500
 #endif

expanding Le Quyen's answer:

You don't need "the git version".

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

  1. open C:\\MingW\\include\\commctrl.h or equivalent.
  2. search /* 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.


Why unset? I don't know but the people giving you MingW are trying to make this clear on their wiki :

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. Possible values for these definitions can be found in the header w32api.h file.

I am trying to compile OpenCV 3.1 with the nonfree modules for Android and I got the message

error: 'pthread_self' was not declared in this scope

It was solved by including "ANDROID_NDK_LAYOUT" with value "RELEASE".

My CMake configuration: CMake configuration

I made a "mingw32-make clean" (just in case) and "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. After many tries, I solved this by simply downloading openCV-3.1.0 instead of 2.4.13.

Prior to moving to openCV-3.1.0, I tried installing code::blocks alone then installing the latest mingw version. Didn't help. I also tried generating the makefile using the 32 bit version of CMake vs the 64 bit version. Didn't help either.

With opencCV-3.1.0, you need not edit any .h files like I read elsewhere. Expect a longer mingw32-make execution time too.

我通过在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

I tried the above suggestion to change Mingw/include/commctrl.h as:

#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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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