在MinGW-W64在线安装程序中,您可以选择几个字段.但是我找不到任何关于此的文件,我所做的猜测并没有给我我想要的行为.
很明显,很多工作已经进入这个项目,所以很可惜因为缺乏基本文档而受到阻碍.
"版本"和"架构"字段是不言自明的,但我遇到的其他字段是(显示为当前安装程序的值):
posix
和win32
dwarf
和sjlj
0
,1
,2
.我在之前的安装中选择的值是win32
,seh
并且1
(从那时起显然选项已经改变,但我不知道什么是什么).
每个选项的优缺点是什么,特别是线程模型和异常处理,以及哪个版本"最佳"?
我遇到的具体问题x86_64-win32-seh-rev1
是:
std::thread
并且std::condition_variable
不受支持我可以解决调试问题但是使用C++ 11线程真的很棒.
我正在编写一个简单的C++程序来演示锁的使用.我正在使用codeblocks
和gnu
gcc
编译器.
#include <iostream>
#include <thread>
#include <mutex>
using namespace std;
int x = 0; // shared variable
void synchronized_procedure()
{
static std::mutex m;
m.lock();
x = x + 1;
if (x < 5)
{
cout<<"hello";
}
m.unlock();
}
int main()
{
synchronized_procedure();
x=x+2;
cout<<"x is"<<x;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:mutex in namespace std does not name a type
.
为什么我收到此错误?编译器是否支持使用锁?
我在安装MinGW-w64工具链时选择了Win32线程模型,在阅读它之后提供了比POSIX更好的性能.我自己没有资格对此声明进行基准测试,但这里有一个来源.
起初我认为这个选项只会影响GCC运行时的内部工作,同时不会阻止我在我的代码中使用C++ 11线程,基于这个答案和其他用户rubenvb的评论.
但是,情况似乎并非如此.在MinGW-w64安装中似乎不存在支持.std::thread
我从命令行调用g ++而没有其他选项-std=c++11
.
此时我不确定是否:
thread
库的代码,或者;std::thread
在我的场景中实际上是支持的,它只是不直观.我强化了标题中的"开箱即用"部分.存在一个名为mingw-std-threads的库,如本答案中所示.但是,作为第三方选项,它与此问题无关.
那么,截至今天(2016年5月)std::thread
,当与Win32内部线程模型一起安装时,MinGW-w64是否支持依赖代码?
问候,
我最近离开了我的unix避难所来测试一个据称是跨平台的网络库,却发现mingw不喜欢被提供给c ++ 11的东西.
我认为我缺少必需的标题,因为Win7没有包含c ++ 11支持.
它与VS2012编译得很好,
但g ++拒绝.
Run Code Online (Sandbox Code Playgroud)error: 'thread' in namespace 'std' does not name a type error: 'mutex' in namespace 'std' does not name a type
问题是:
如何获取c ++ 11头文件/库的副本,即<thread>,而不使用VS2012安装提供的文件.
PS#1我试过mingw-get update但它仍然找不到<thread>
PS#2我也在使用-std = c ++ 11
真诚的,
Chris.
我从官方网站下载了MinGW版本:http://sourceforge.net/projects/mingw/files/并将其安装在我的Windows 7机器上.
运行g++ --version
给了我g++.exe (GCC) 4.8.1
,我相信GCC 4.8.1支持C++ 11功能,包括线程.
运行g++ -std=c++11 main.cpp
成功编译以下程序.
//main.cpp
#include <memory>
int main() {
std::unique_ptr<int> a(new int);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但运行g++ -std=c++11 main.cpp
以下程序:
//main.cpp
#include <mutex>
int main() {
std::mutex myMutex;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
给出错误:
main.cpp: In function `int main()`:
main.cpp:5:5: error: 'mutex' is not a member of 'std'
std::mutex myMutex;
^
main.cpp:5:16: error: expected ';' before 'myMutex'
std::mutex myMutex;
^
Run Code Online (Sandbox Code Playgroud)
好像<mutex>
不受支持.编译器没有抱怨#include …
我正在尝试为Windows编译一个简单的应用程序:
#include <thread>
void Func(){
return;
}
int main(){
std::thread thr1(Func);
thr1.detach();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
$ i686-w64-mingw32-g++ -static-libstdc++ -static-libgcc -pipe -g -std=c++0x ./threadstutor.cpp
./threadstutor.cpp: In function ‘int main()’:
./threadstutor.cpp:8:3: error: ‘thread’ is not a member of ‘std’
./threadstutor.cpp:8:15: error: expected ‘;’ before ‘thr1’
./threadstutor.cpp:9:3: error: ‘thr1’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
实际上,如果使用g ++为Ubuntu编译,这段代码没有这样的问题; 但是我需要为Windows进行交叉编译,而在这里我被卡住了.
我想下载最新版本的gcc 4.7.2
Windows编译器.
当我到这个页面在这里我本来是要看到一个下载链接,我面临着两大类:
这两者之间有什么区别?
它们只是线程实现吗?我的意思是它们只是在实现方式上有所不同,因此结束结果(类,如何使用它们等)保持不变?
或者他们是否强加了特定的编码风格?
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线程支持
非常感谢您的帮助.谢谢.
如果我想在 Windows 10 下使用 robotsgo 运行任何代码,我会收到以下错误:
# github.com/go-vgo/robotgo
In file included from ./bitmap/../base/str_io_c.h:2:0,
from ./bitmap/goBitmap.h:17,
from ..\go\src\github.com\go-vgo\robotgo\robotgo.go:45:
./bitmap/../base/zlib_util_c.h:2:18: fatal error: zlib.h: No such file or directory
compilation terminated.
Run Code Online (Sandbox Code Playgroud)
我的路径变量:
https://i.stack.imgur.com/FTXBB.png
遵循安装并检查问题。
https://github.com/go-vgo/robotgo#installation
有人在这里遇到了类似的错误:https ://github.com/go-vgo/robotgo/issues/100
但他们的修复“已解决,应更改 %PATH% 中的 gcc 编译器”对我不起作用。
import (
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.ScrollMouse(10, "up")
robotgo.MouseClick("left", true)
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
}
Run Code Online (Sandbox Code Playgroud) 我正在使用MinGW 5.3.0和Crypto ++ 5.6.5:
C:\MinGW>g++ -std=c++11 -s -D_WIN32_WINNT=0x0501 LOG.cpp -U__STRICT_ANSI__ Decclass.cpp \
-IC:\\MinGW\\ -IC:\\MinGW\\boost -LC:\\MinGW -lssl -lcrypto -lcryptopp -lgdi32 -lPCRYPT \
-lz -ltiny -lwsock32 -lws2_32 -lShlwapi
Run Code Online (Sandbox Code Playgroud)
编译会导致以下错误。
c:\mingw\cryptopp565\include\cryptopp\misc.h:287:14: error: 'mutex' in namespace 'std'
does not name a typestatic std::mutex s_mutex;
c:\mingw\cryptopp565\include\cryptopp\misc.h:296:18: error: 'mutex' is not a member of
'std'std::lock_guard<std::mutex> lock(s_mutex);
Run Code Online (Sandbox Code Playgroud)
它显示“ mutex”不是“ std”的成员
我需要其他版本的MinGW吗?还是我可以自己修复此版本?
我将其作为多线程示例的简化版本编写以了解它,但在编译时遇到了一些问题。我的编译器说它thread
不是 的成员std
并提示我添加#include <thread>
到我的代码中,即使我已经这样做了。到目前为止,我一直无法找到任何类似的问题,但我怀疑这是我编译它的方式的问题,因为我的代码与示例代码非常相似。
#include <iostream>
#include <thread>
void doWork () {
std::cout << "Working...\n";
}
int main () {
std::thread worker(doWork);
work.join();
std::cout << "Finished\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的编译器是MinGW的G ++ 9.2.0
我编译g++ main.cpp -o main
它给了我这些错误:
main.cpp: In function 'int main()':
main.cpp:9:7: error: 'thread' is not a member of 'std'
9 | std::thread worker(doWork);
| ^~~~~~
main.cpp:3:1: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
2 | #include …
Run Code Online (Sandbox Code Playgroud) 我已经在很多网站上搜索过这个,但都失败了。但是TDM在“TDM-gcc”中代表什么?当我想选择 gcc 作为编译器时,我很困惑。那么,有什么区别呢?我应该选择TDM还是NON-TDM?还是 TDM 仅适用于 minGW?在 Windows 平台上?
官方 TDM-gcc 站点甚至不解释它...