簡體   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