首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++11线程boost容器

C++11线程boost容器
EN

Stack Overflow用户
提问于 2015-03-18 12:21:20
回答 1查看 173关注 0票数 3

带有C++11线程的简单代码:

代码语言:javascript
复制
#include <iostream>
#include <thread>
#include <string>

using namespace std;
void thread_task(){
    std::cout<<"hello, here is thread task with state:"<<std::endl;
}

int main(int argc, char *argv[])
{
    std::thread t(thread_task);
    t.join();
    return 0;
}

汇编:

代码语言:javascript
复制
g++ -pthread -std=c++11 -O0 -Wall -g -ggdb  main.cpp  -o main  -lboost_system -lboost_filesystem -lboost_serialization

./main can execute right!

--

代码语言:javascript
复制
g++ -pthread -std=c++11 -O0 -Wall -g -ggdb  main.cpp  -o main  -lboost_system -lboost_filesystem -lboost_serialization -lboost_container-mt

g++ -pthread -std=c++11 -O0 -Wall -g -ggdb  main.cpp  -o main  -lboost_system -lboost_filesystem -lboost_serialization -lboost_container 

./main all will have an error:
terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted
[1]    29643 abort (core dumped)  ./main

为什么-lboost_container会导致这个错误?当然,在我的代码示例中不需要boost_container。这是一个例子。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-16 03:08:38

这是here的回答

代码语言:javascript
复制
g++ -Wl,--no-as-needed -pthread -std=c++11 -O0 -Wall -g -ggdb  main.cpp  -o main  -lboost_system -lboost_filesystem -lboost_serialization -lboost_container
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29121925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档