0
此代碼:爲什麼這段代碼不能用clang構建,使用gcc崩潰,但在VC++下運行良好?
#include <iostream>
#include <future>
int main()
{
std::async([]{std::cout << "hello\n";}).get();
}
運行正常,並打印hello
用Visual C++ 2013,但將引發異常用gcc生產:
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
和甚至不帶鐺構建,生產這種錯誤消息:
/usr/bin/ld: /tmp/source-83f28e.o: undefined reference to symbol '[email protected]@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我用rexter來運行測試。你能解釋這種行爲嗎?
編輯
隨着-pthread
編譯選項gcc版本運行良好,現在鐺版本構建和生產:
hello
exception_ptr not yet implemented
你使用過'-pthread'標誌嗎? – juanchopanza 2014-11-23 23:48:57
這不是一個真正的「崩潰」。 – 2014-11-23 23:58:08
@ juanchopanza _marked as duplicate_這是正確的,特別是在事後的幫助下。鐺錯誤消息導致鏈接器選項,但gcc消息 - 根本不。 – 2014-11-24 00:33:52