我正在Windows上安装mingw-w64,有两个选项:win32线程和posix线程.我知道win32线程和pthreads之间的区别是什么,但我不明白这两个选项之间的区别.我怀疑如果我选择posix线程,它将阻止我调用WinTI函数,如CreateThread.
看来这个选项指定某些程序或库将使用哪个线程API,但是通过什么?通过GCC,libstdc ++还是别的什么?
我发现了这个: 在windows的gcc端口中thread_posixs和thread_win32之间的区别是什么?
简而言之,对于这个版本的mingw,threads-posix版本将使用posix API并允许使用std :: thread,而threads-win32将使用win32 API,并禁用std :: thread部分标准.
好的,如果我将选择win32线程,那么std :: thread将不可用,但仍将使用win32线程.但用什么?
std::thread在MinGW中使用g ++ 4.5.2进行编译时,有没有在Windows中使用C++ 11标准库?
我会假设没有,因为我已经看到许多事情说你必须使用pthreads选项进行编译,但我想我还是会问.
我从官方网站下载了MinGW并将其安装在我的Windows 8.1机器上.
运行g ++ --version给了我g ++.exe(GCC)4.8.1.
我正在尝试编译MinGW编译器中的现有代码库,但它失败并出现以下错误:
error: 'mutex' in namespace 'std' does not
name a type
private: std::mutex m_Mutex;
^
error: 'condition_variable' in namespace 's
Run Code Online (Sandbox Code Playgroud)
以及与锁定和线程相关的更多错误.
我能够在Cygwin-64中编译相同的代码库而没有任何问题.我需要在MinGW中成功构建和编译,以便创建一些在MSVS上兼容的.dll文件.
我已经提到了以下链接,但我无法通过解决方案.
使用mingw和g ++使用std :: thread/mutex在Win7下工作4.7.2
MinGW 4.8.1 C++ 11线程支持
非常感谢您的帮助.谢谢.
我正在尝试使用额外的java(ximgproc)模块编译opencv.用Cmake生成文件后,我尝试使用带有cmd的"mingw32-make"命令生成.jar和.dll,但是我收到了以下错误.
我正在关注本指南:https://zami0xzami.wordpress.com/2016/03/16/building-java-wrapper-for-opencv/
我该如何解决?
C:\Users\Jt1995\Desktop\opencv-master\modules\objdetect\src\detection_based_tracker.cpp:175:14: error: 'thread' in namespace 'std' does not name a type
std::thread second_workthread;
^~~~~~
C:\Users\Jt1995\Desktop\opencv-master\modules\objdetect\src\detection_based_tracker.cpp:176:14: error: 'mutex' in namespace 'std' does not name a type
std::mutex mtx;
^~~~~
C:\Users\Jt1995\Desktop\opencv-master\modules\objdetect\src\detection_based_tracker.cpp:177:14: error: 'condition_variable' in namespace 'std' does not name a type
std::condition_variable objectDetectorRun;
^~~~~~~~~~~~~~~~~~
C:\Users\Jt1995\Desktop\opencv-master\modules\objdetect\src\detection_based_tracker.cpp:178:14: error: 'condition_variable' in namespace 'std' does not name a type
std::condition_variable objectDetectorThreadStartStop;
^~~~~~~~~~~~~~~~~~
C:\Users\Jt1995\Desktop\opencv-master\modules\objdetect\src\detection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::setParameters(const cv::DetectionBasedTracker::Parameters&)':
C:\Users\Jt1995\Desktop\opencv-master\modules\objdetect\src\detection_based_tracker.cpp:143:30: error: 'mutex' is not a member of 'std'
std::unique_lock<std::mutex> mtx_lock(mtx); …Run Code Online (Sandbox Code Playgroud) 简单的程序就像这样
#include <iostream> // std::cout
#include <thread> // std::thread
#include <mutex> // std::mutex
std::mutex mtx; // mutex for critical section
int main ()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
尝试以下编译
$ /usr/local/Cellar/gcc46/4.6.4/bin/g++-4.6 -std=gnu++0x -I/usr/local/Cellar/gcc46/4.6.4/gcc/include/c++ -L/usr/local/Cellar/gcc46/4.6.4/gcc/lib temp_mutex.cpp
temp_mutex.cpp:6:1: error: 'mutex' in namespace 'std' does not name a type
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我在Mac上编译.
当我在ubuntu中使用arm-none-eabi-g ++工具链尝试以下代码时,我遇到了编译错误:
#include <iostream>
#include <thread> // std::thread
#include <mutex> // std::mutex
mutex mtx; // mutex for critical section
int main ()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
commpile命令:
arm-none-eabi-g++ -Os -Wall -std=c++11 -fno-rtti -fno-exceptions -c mt.cc
Run Code Online (Sandbox Code Playgroud)
编译错误:
mt.cc:5:1:错误:'mutex'没有命名类型mutex mtx; //关键部分的互斥锁
^
gcc版本:
gcc版本4.8.4 20140725(发布)[ARM/embedded-4_8-branch修订版213147](适用于ARM嵌入式处理器的GNU工具)