使用clang编译c ++ 11启用失败

时间:2013-05-21 01:40:11

标签: c++ macos c++11 clang

拥有以下test.cpp

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

使用最新的GCC(4.8.0)g++ test.cpp -std=c++11(gcc也失败)进行构建时,文件将进行编译。尝试使用最新的clang编译

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模式下工作做些什么?

1 个答案:

答案 0 :(得分:5)

clang适用于C.对于C ++,请使用clang++

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