4

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
3
  • Looks like a bug in the code. Commented Sep 13, 2016 at 6:24
  • you got 1337 in your post id Commented Jan 14, 2017 at 20:55
  • I'm on openCV 3.2.0 using Windows 10 and still have the problem noted here with pthread_self(). Seems this hasn't been fixed in later versions - assuming it is an openCV problem (vs. a MinGW problem). Commented May 30, 2017 at 20:50

6 Answers 6

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

misc: you could've copied that code on-site (to stackoverflow.com) as text
1

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.

Comments

1

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.

1 Comment

Do you still get parallel execution building this way or are you stuck with one core?
0

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"

Comments

0

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.

1 Comment

I'm on Windows 10 with openCV-3.2.0. also having this problem. Do I need to go back to 3.1.0 to make this work? (I would have thought that it would continue working on the later version that I have.)
0

I resolved the pthread_self error by unchecking WITH_PTHREADS_PF in CMake

1 Comment

Do you still get parallel execution (presumably with something other than pthreads) or does this cause it to run on one core?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.