【问题标题】:Compiling with clang with c++11 enabled fails在启用 c++11 的情况下使用 clang 编译失败
【发布时间】:2013-05-21 01:40:10
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,现在看来很明显了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 2019-05-29
    • 2019-08-14
    • 2020-12-05
    • 2012-05-05
    相关资源
    最近更新 更多