繁体   English   中英

C ++ 11线程提升容器

[英]C++11 thread boost container

一个简单的C ++ 11线程代码:

#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;
}

编译:

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

./main can execute right!

-

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。 这只是一个例子。

这回答了这里

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM