2013-05-21 68 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