带有c++ 11线程的Qtcreator
Qtcreator with C++11 thread
我为c++ 11线程编写了hello world程序。我正在使用qtcreator ide与gcc 4.9.1,但我无法运行该程序。它可以正确编译。但是当我运行时,它给出以下警告
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
我的项目。Pro文件
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11
LIBS += -pthread
and main.cpp is
#include <iostream>
#include <thread>
void hello()
{
std::cout<<"Hello Concurrent Worldn";
}
int main()
{
std::thread t(hello);
t.join();
}
我注意到它使用了
g++ -c -pipe -std=c++11 -g -Wall -W -fPIE -I/usr/lib/qt/mkspecs/linux-g++ -I. -o main.o main.cpp
创建main。0对象文件和
g++ -Wl,-O1,--sort-common,--as-needed,-z,relro -o project main.o -pthread
创建可执行文件。如果从用于创建可执行文件的命令中删除——as-needed。它工作得很好。请让我知道正确的解决方案,以便我可以使用qtcreator为c++ 11线程。
这是libstdc++中的一个bug。作为解决方法,如果使用c++线程,请不要使用--as-needed
。
。
相关文章:
- 从不同线程使用int64的不同字节安全吗
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 在C++中使用cURL和多线程
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在cuda线程之间共享大量常量数据
- 如何将元素添加到数组的线程安全函数?
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 异常属于C++中的线程还是进程
- C++中的线程安全删除
- C++使用params创建线程函数会导致转换错误
- 类与私有变量的其他类之间的线程安全性
- CoInitialize()在单独的线程上崩溃而不返回
- c++中的线程池
- 线程之间的布尔停止信号
- 为什么std::async使用同一个线程运行函数
- 用于矢量处理的多个线程
- C++为线程工作动态地分割例程
- 带有c++ 11线程的Qtcreator