0

具有以下内容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 模式下工作?

4

1 回答 1

5

clang用于 C。对于 C++,使用clang++.

clang++ test.cpp -std=c++11
于 2013-05-21T01:50:58.440 回答