2013-01-01 2 views
22

C++ 11 <thread> 헤더에 의존하는 다음 C++ 프로그램을 컴파일하려고합니다. OSX Lion에서이 작업을 수행하려고합니다.OSX lion에서 clang 3.2를 사용하여 C++ 11을 컴파일하는 방법은 무엇입니까?

#include <iostream> 
#include <thread> 
#include <vector> 

void hello() 
{ 
    std::cout << "Hello from thread " << std::this_thread::get_id() << std::endl; 
} 

int main() 
{ 
    std::vector<std::thread> threads; 

    for(int i = 0; i < 5; i++) 
    { 
     threads.push_back(std::thread(hello)); 
    } 

    for(auto& thread: threads) 
    { 
     thread.join(); 
    } 

    return 0; 
} 

위의 프로그램은 homebrew 패키지 관리자를 사용하여 설치 한 g ++ 4.7로 정상적으로 컴파일됩니다. 그 소리 3.2 위의 프로그램을 컴파일 할 때 그러나 나는 다음과 같은 오류 메시지가 (또한 사제 패키지 관리자를 사용하여 설치) 다음 <thread> 헤더를 찾을 수 없습니다

Zameers-MacBook-Air:tmp zmanji$ clang++ -v -std=c++11 test.cpp 
clang version 3.2 (tags/RELEASE_32/final) 
Target: x86_64-apple-darwin11.3.0 
Thread model: posix 
"/usr/local/Cellar/llvm/3.2/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 128.2 -v -resource-dir /usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2 -fmodule-cache-path /var/folders/qf/j_7_sw0n093gn1y0mtsyztxh0000gn/T/clang-module-cache -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zmanji/tmp -ferror-limit 19 -fmessage-length 101 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.7.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/qf/j_7_sw0n093gn1y0mtsyztxh0000gn/T/test-Zkjucl.o -x c++ test.cpp 
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-apple-darwin11.3.0 
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64" 
ignoring nonexistent directory "/usr/include/c++/4.0.0" 
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/" 
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward" 
#include "..." search starts here: 
#include <...> search starts here: 
/usr/include/c++/4.2.1 
/usr/include/c++/4.2.1/backward 
/usr/local/include 
/usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2/include 
/usr/include 
/System/Library/Frameworks (framework directory) 
/Library/Frameworks (framework directory) 
End of search list. 
test.cpp:2:10: fatal error: 'thread' file not found 
#include <thread> 
     ^
1 error generated. 

그것은 그 연타 것을하지만 난 이유를 모르겠습니다.

편집

: 나는 아래 sharth의 답변을 시도하고 지금은 <iostream> 헤더가 존재하지 않는 오류를 얻고있다.

Zameers-MacBook-Air:tmp zmanji$ clang++ -v -std=c++11 -stdlib=libc++ test.cpp 
clang version 3.2 (tags/RELEASE_32/final) 
Target: x86_64-apple-darwin11.3.0 
Thread model: posix 
"/usr/local/Cellar/llvm/3.2/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 128.2 -v -resource-dir /usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2 -fmodule-cache-path /var/folders/qf/j_7_sw0n093gn1y0mtsyztxh0000gn/T/clang-module-cache -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zmanji/tmp -ferror-limit 19 -fmessage-length 203 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.7.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/qf/j_7_sw0n093gn1y0mtsyztxh0000gn/T/test-k2Alf4.o -x c++ test.cpp 
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-apple-darwin11.3.0 
ignoring nonexistent directory "/usr/local/Cellar/llvm/3.2/bin/../lib/c++/v1" 
ignoring nonexistent directory "/usr/include/c++/v1" 
#include "..." search starts here: 
#include <...> search starts here: 
/usr/local/include 
/usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2/include 
/usr/include 
/System/Library/Frameworks (framework directory) 
/Library/Frameworks (framework directory) 
End of search list. 
test.cpp:1:10: fatal error: 'iostream' file not found 
#include <iostream> 
     ^
1 error generated. 
+0

가 나는''-pthread' 및하다고 생각 -std = C++이 나를 위해 작동하지 않습니다 11' – Rapptz

답변

43

당신은 libc++ 대신 libstdc++ 사용해야합니다.

clang++ -std=c++11 -stdlib=libc++ foo.cc 
+0

. 내가 지금 받고있는 오류 메시지에 대한 편집을 참조하십시오. –

+3

당신은 시스템 clang을 사용하고 있지 않습니다. 당신은 homebrew clang을 사용하고 있습니다. 어떤 이유로 든/usr/include/C++/v1에서 libC++를 찾고 있는데, 이는 리눅스에 설치하는 것이 좋습니다. OS X에서는/usr/lib/C++/v1에 저장됩니다.이 위치는 시스템이 손상되는 곳입니다. –

+0

네, 제 의견에 언급했습니다. libC++와 homebrew clang을 사용할 수 있습니까? –

관련 문제