compile with mingw in linux i get this error in function main': dnn.cpp:(.text+0x5f):…
- User
compile with mingw in linux i get this error in function
main': dnn.cpp:(.text+0x5f): undefined reference tocv::dnn::dnn4_v20240521::readNetFromONNX(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' /usr/bin/ld: dnn.cpp:(.text+0x6e): undefined reference tocv::dnn::dnn4_v20240521::Net::empty() const' /usr/bin/ld: dnn.cpp:(.text+0x103): undefined reference tocv::imread(std::_cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)' /usr/bin/ld: dnn.cpp:(.text+0x112): undefined reference tocv::Mat::empty() const' /usr/bin/ld: dnn.cpp:(.text+0x1f6): undefined reference tocv::dnn::dnn4_v20240521::blobFromImage(cv::InputArray const&, double, cv::Size const&, cv::Scalar const&, bool, bool, int)' /usr/bin/ld: dnn.cpp:(.text+0x290): undefined reference tocv::dnn::dnn4_v20240521::Net::setInput(cv::_InputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, cv::Scalar_<double> const&)' /usr/bin/ld: dnn.cpp:(.text+0x2ec): undefined reference tocv::dnn::dnn4_v20240521::Net::forward(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' /usr/bin/ld: dnn.cpp:(.text+0x30f): undefined reference tocv::noArray()' /usr/bin/ld: dnn.cpp:(.text+0x32f): undefined reference tocv::Mat::reshape(int, int) const' /usr/bin/ld: dnn.cpp:(.text+0x372): undefined reference tocv::minMaxLoc(cv::_InputArray const&, double*, double*, cv::Point_<int>*, cv::Point_<int>*, cv::_InputArray const&)' /usr/bin/ld: dnn.cpp:(.text+0x38d): undefined reference tocv::Mat::~Mat()' /usr/bin/ld: dnn.cpp:(.text+0x411): undefined reference tocv::Mat::~Mat()' /usr/bin/ld: dnn.cpp:(.text+0x420): undefined reference tocv::Mat::~Mat()' /usr/bin/ld: dnn.cpp:(.text+0x42f): undefined reference tocv::Mat::~Mat()' /usr/bin/ld: dnn.cpp:(.text+0x44d): undefined reference tocv::dnn::dnn4_v20240521::Net::~Net()' /usr/bin/ld: dnn.cpp:(.text+0x517): undefined reference tocv::Mat::~Mat()' /usr/bin/ld: dnn.cpp:(.text+0x52b): undefined reference tocv::Mat::~Mat()' /usr/bin/ld: dnn.cpp:(.text+0x53f): undefined reference tocv::Mat::~Mat()' /usr/bin/ld: dnn.cpp:(.text+0x553): undefined reference tocv::Mat::~Mat()' /usr/bin/ld: dnn.cpp:(.text+0x57b): undefined reference to `cv::dnn::dnn4_v20240521::Net::~Net()' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/panel2CnnMain.dir/build.make:97: panel2CnnMain] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/panel2CnnMain.dir/all] Error 2 make: *** [Makefile:91: all] Error 2 - Assistant
The error you're experiencing is due to missing references during the linking stage, indicating that the linker cannot find the definitions for several OpenCV functions. This typically happens when the OpenCV libraries are not correctly linked to your C++ project. Here’s how you can resolve this issue:
- User
In file included from /usr/local/include/opencv4/opencv2/core.hpp:3419, from /media/ali/T7/AI/yoloCPPWin/include/wopencv/build/include/opencv2/core/core.hpp:48, from /media/ali/T7/AI/yoloCPPWin/dnn.cpp:2: /usr/local/include/opencv4/opencv2/core/utility.hpp:788:14: error: ‘recursive_mutex’ in namespace ‘std’ does not name a type 788 | typedef std::recursive_mutex Mutex; | ^~~~~~~~~~~~~~~ /usr/local/include/opencv4/opencv2/core/utility.hpp:63:1: note: ‘std::recursive_mutex’ is defined in header ‘’; did you forget to ‘#include ’? 62 | #include // std::mutex, std::lock_guard +++ |+#include 63 | #endif /usr/local/include/opencv4/opencv2/core/utility.hpp:789:29: error: ‘Mutex’ is not a member of ‘cv’ 789 | typedef std::lock_guardcv::Mutex AutoLock; | ^~~~~ /usr/local/include/opencv4/opencv2/core/utility.hpp:789:34: error: template argument 1 is invalid 789 | typedef std::lock_guardcv::Mutex AutoLock; | ^ make[2]: *** [CMakeFiles/panel2CnnMain.dir/build.make:76: CMakeFiles/panel2CnnMain.dir/dnn.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/panel2CnnMain.dir/all] Error 2 make: *** [Makefile:91: all] Error 2
- Assistant
The errors you're encountering suggest that the C++ standard library mutex is not being recognized, which is likely due to not using a standard that supports
std::recursive_mutex. Thestd::recursive_mutextype was introduced in C++11, so you need to ensure that your compiler is using at least the C++11 standard.Here’s how you can address these issues:
-
Specify C++ Standard:
-
If you are using CMake, make sure to specify the C++ standard in your :
-
-
- User
[ 50%] Building CXX object CMakeFiles/panel2CnnMain.dir/dnn.cpp.obj In file included from /media/ali/T7/AI/yoloCPPWin/include/wopencv/build/include/opencv2/core.hpp:3417, from /media/ali/T7/AI/yoloCPPWin/dnn.cpp:2: /media/ali/T7/AI/yoloCPPWin/include/wopencv/build/include/opencv2/core/utility.hpp:718:14: error: ‘recursive_mutex’ in namespace ‘std’ does not name a type 718 | typedef std::recursive_mutex Mutex; | ^~~~~~~~~~~~~~~ /media/ali/T7/AI/yoloCPPWin/include/wopencv/build/include/opencv2/core/utility.hpp:63:1: note: ‘std::recursive_mutex’ is defined in header ‘’; did you forget to ‘#include ’? 62 | #include // std::mutex, std::lock_guard +++ |+#include 63 | #endif /media/ali/T7/AI/yoloCPPWin/include/wopencv/build/include/opencv2/core/utility.hpp:719:29: error: ‘Mutex’ is not a member of ‘cv’ 719 | typedef std::lock_guardcv::Mutex AutoLock; | ^~~~~ /media/ali/T7/AI/yoloCPPWin/include/wopencv/build/include/opencv2/core/utility.hpp:719:34: error: template argument 1 is invalid 719 | typedef std::lock_guardcv::Mutex AutoLock; | ^ make[2]: *** [CMakeFiles/panel2CnnMain.dir/build.make:77: CMakeFiles/panel2CnnMain.dir/dnn.cpp.obj] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/panel2CnnMain.dir/all] Error 2
- Assistant
The errors you're encountering are due to the
std::recursive_mutextype not being recognized, and this might happen if it's not included due to incorrect compiler settings or missing header files.Here are the steps to resolve this issue:
-
Ensure Correct C++ Standard:
- It seems you're using MinGW for cross-compilation. Make sure that MinGW's version of GCC supports at least C++11. You need to pass the correct flags to the compiler:
-
- User
n file included from /usr/local/include/opencv4/opencv2/core.hpp:3419, from /media/ali/T7/AI/yoloCPPWin/dnn.cpp:2: /usr/local/include/opencv4/opencv2/core/utility.hpp:788:14: error: ‘recursive_mutex’ in namespace ‘std’ does not name a type 788 | typedef std::recursive_mutex Mutex;
- Assistant
The error message you're receiving indicates that the compiler does not recognize . This is often due to missing includes or incorrect compiler flags. Here’s a step-by-step guide to resolve this issue:
- User
i compileinng in linux for windows i got error: ‘recursive_mutex’ in namespace ‘std’ does not name a type 788 | typedef std::recursive_mutex Mutex;
- Assistant