2013-10-30 26 views
-3

這是來自ubuntu 13.10和g ++ 4.8的一個bug,所以我關閉了這個問題。cpp線程程序無法運行-fprofile-arcs

within -Wl,--no-as-needed. 

我頭上有什麼問題。 我得到了一些類似的代碼

#include <iostream> 
#include <thread> 

int main(int argc, char* argv[]) 
{ 
    { 
     std::thread t1([&]{ std::cout << "hello " << std::endl; }); 
     t1.join();   
    } 
    return 0; 
} 

,這裏是我的編譯命令:

g++ -std=c++0x -lpthread test.cpp 

PS:我已經改變我的鏈接順序爲所有種類的順序。

它適用於G ++ 4.7和Ubuntu 13.04 但它在G ++ 4.8.1拋出SYSTEM_ERROR和Ubuntu 12.10

,直到我用-fprofile弧它工作得很好編譯。

只是波紋管:

g++ test.cpp -std=c++0x -fprofile-arcs -pthread 
a.out 
hello 

g++ test.cpp -std=c++0x -pthread 
a.out 
terminate called after throwing an instance of 'std::system_error' 

什麼():啓用多線程使用std ::線程:操作不允許

+0

它在編譯或鏈接失敗嗎? – tristan

+0

假設鏈接,導致運行時發生錯誤 – sinsaychen

+0

編譯爲'g ++ -std = C++ 0x test.cpp -lpthread'時正常工作。當編譯爲'g ++ -std = C++ 0x -lpthread test.cpp'時拋出「operation not permitted」系統異常。 – Duck

回答

0

就跨越了Ubuntu的12.10虛擬機

[email protected] ~/src $ g++-4.8 --version 
g++ (Ubuntu 4.8.1-2ubuntu1~12.10) 4.8.1 
Copyright (C) 2013 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

而且用此命令行編譯:

[email protected] ~/src $ g++-4.8 -std=c++11 -o test.exe test.cpp -pthread -lpthread 
[email protected] ~/src $ ./test.exe 
hello 
+0

是的,我的ubuntu 13.04也可以,但在13.10中運行fialue。 – sinsaychen