2013-05-21 99 views
0

具有以下test.cpp與C++ 11鐺編譯啓用失敗

#include <iostream> 
int main() { 
     int a{}; 
     std::cout << "TEST" << std::endl; 
} 

當構建了最新的海灣合作委員會(4.8.0)g++ test.cpp -std=c++11(GCC也失敗),該文件編譯。試圖用最新的鐺編譯

clang version 3.4 (trunk 182322) 
Target: x86_64-apple-darwin12.3.0 
Thread model: posix 

構建失敗:

clang test.cpp -std=c++11 

Undefined symbols for architecture x86_64: 
    "std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from: 
     _main in test-NcubkF.o 
    "std::ios_base::Init::Init()", referenced from: 
     ___cxx_global_var_init in test-NcubkF.o 
    "std::ios_base::Init::~Init()", referenced from: 
     ___cxx_global_var_init in test-NcubkF.o 
    "std::cout", referenced from: 
     _main in test-NcubkF.o 
    "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from: 
     _main in test-NcubkF.o 
    "std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from: 
     _main in test-NcubkF.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

有什麼可以做的clang(或gcc)在工作的C++ 11模式?

回答

5

clang用於C.對於C++,請使用clang++

clang++ test.cpp -std=c++11 
+0

謝謝,現在看起來很明顯。 – Appleshell