Opencv compile failed with error Mutex in namespace 'cv', when using arm-none-eabi-gcc compiler

Hi all,

I’ve been trying to cross compile opencv using the arm-none-eabi-gcc/g++ and I got stuck when the compilation came across the cv::Mutex implementation. It throws the following error

In file included from /home/kowshik/Desktop/opencv_porting/opencv/modules/core/src/algorithm.cpp:43:
/home/kowshik/Desktop/opencv_porting/opencv/modules/core/src/precomp.hpp:369:5: error: 'Mutex' in namespace 'cv' does not name a type
  369 | cv::Mutex& getInitializationMutex();
      |     ^~~~~

I tried using the WITH_PTHREADS_PF flag in opencv but it didn’t help either. Please let me know how can I overcome this, and also if any more info is required.

May be same context here

Hi, this post doesn’t help me because I am not using mingW. I am using arm-none-eabi-gcc (a MCU flavoured compiler released by ARM)

however, it seems your compiler has a similar problem (lack of support for posix threads / Mutex)


Mingw-w64 is an advancement of the original project, created to support the GCC compiler on Windows systems. It has forked it in 2007 in order to provide support for 64 bits and new APIs. It has since then gained widespread use and distribution.

I’m using a Linux environment so I don’t think mingw is a major discussion here.

I understood this after trying to compile a simple mutex cpp program and I received the same error. However how do I proceed from here? I don’t think it’s an impossible task because I’ve seen multiple people porting opencv to MCU platforms.

Update: I finally solved it after passing -DOPENCV_DISABLE_THREAD_SUPPORT=ON

Here’s my full cmake command if someone is interested

cmake 									\
-DWITH_IPP=OFF 							\
-DWITH_TBB=OFF 							\
-DWITH_1394=OFF 						\
-DWITH_GTK=OFF 							\
-DBUILD_PNG=ON 							\
-DWITH_V4L=OFF 							\
-DWITH_ITT=OFF 							\
-DBUILD_LIST=core,imgproc,imgcodecs		\
-DBUILD_opencv_python=OFF 				\
-DBUILD_opencv_java=OFF 				\
-DBUILD_opencv_apps=OFF					\
-DCV_TRACE=OFF							\
-DCMAKE_TOOLCHAIN_FILE=/home/kowshik/Desktop/opencv_porting/attr.cmake \

Thanks for the support.

1 Like