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)

https://www.google.com/search?q=arm-none-eabi-gcc%2Fg%2B%2B+posix+support+pthread

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

but

Mingw-w64 is an advancement of the original mingw.org 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 									\
-DCMAKE_BUILD_TYPE=Release				\
-DOPENCV_DISABLE_THREAD_SUPPORT=ON      \
-DBUILD_SHARED_LIBS=OFF 				\
-DCV_DISABLE_OPTIMIZATION=OFF 			\
-DWITH_IPP=OFF 							\
-DWITH_TBB=OFF 							\
-DWITH_OPENMP=OFF 						\
-DWITH_PTHREADS_PF=OFF 					\
-DWITH_QUIRC=OFF 						\
-DWITH_1394=OFF 						\
-DWITH_CUDA=OFF 						\
-DWITH_OPENCL=OFF 						\
-DWITH_OPENCLAMDFFT=OFF 				\
-DWITH_OPENCLAMDBLAS=OFF 				\
-DWITH_VA_INTEL=OFF 					\
-DWITH_EIGEN=OFF						\
										\
-DWITH_GSTREAMER=OFF 					\
-DWITH_GTK=OFF 							\
-DWITH_JASPER=OFF 						\
-DWITH_JPEG=OFF 						\
-DWITH_WEBP=OFF 						\
-DBUILD_ZLIB=ON							\
-DBUILD_PNG=ON 							\
-DWITH_TIFF=OFF 						\
-DWITH_V4L=OFF 							\
-DWITH_LAPACK=OFF						\
-DWITH_ITT=OFF 							\
-DWITH_PROTOBUF=OFF 					\
-DWITH_IMGCODEC_HDR=OFF 				\
-DWITH_IMGCODEC_SUNRASTER=OFF 			\
-DWITH_IMGCODEC_PXM=OFF 				\
-DWITH_IMGCODEC_PFM=OFF 				\
										\
-DBUILD_LIST=core,imgproc,imgcodecs		\
-DBUILD_JAVA=OFF						\
-DBUILD_opencv_python=OFF 				\
-DBUILD_opencv_java=OFF 				\
										\
-DBUILD_opencv_apps=OFF					\
-DBUILD_PACKAGE=OFF						\
-DBUILD_PERF_TESTS=OFF					\
-DBUILD_TESTS=OFF						\
-DCV_ENABLE_INTRINSICS=OFF				\
-DCV_TRACE=OFF							\
-DOPENCV_ENABLE_MEMALIGN=OFF			\
										\
-DCMAKE_TOOLCHAIN_FILE=/home/kowshik/Desktop/opencv_porting/attr.cmake \
..

Thanks for the support.

1 Like