2014-06-17 24 views
3

正如我已閱讀g++-4.9改進的鏈接時間優化支持,我想試試看。不幸的是,我在運行時遇到異常,具體是std::system_errore.what() == Enable multithreading to use std::thread: Operation not permitted鏈接時間優化與多線程支持衝突

現在我通常知道如何解決該錯誤:將-pthread添加到我的編譯器調用中,但事實上,我已經有了這個參數!

我的示例代碼是:

編譯時
#include <thread> 

int main() 
{ 
    std::thread t([](){}); // do nothing in a thread! 
    t.join();    // wait for nothing to be done 
} 

(X是7,8或9)如預期完美無缺

g++-4.X -std=c++11 -pthread test.cpp -o thread_test_fine 

作品,沒有運行時錯誤。

然而,

g++-4.X -std=c++11 -pthread -flto test.cpp -o thread_test_runtime_error 

失敗,並system_error例外。

問:

這種行爲意圖(有什麼解決?),或者是一個錯誤嗎?

(在此之前,問題也會隨之而來:我的編譯器都與--enable-threads=posix建)

+0

你的鏈接是什麼? – quantdev

+0

@quantdev我想這就是GNU ld(GNU Binutils for Ubuntu)2.24.51.20140612(我其實從來沒有關心過這個鏈接器,所以我很喜歡這個)no – stefan

回答