clang iostream - 未找到符号

时间:2012-04-14 19:19:17

标签: c++ linker iostream clang

所以我试图让clang编译器工作..我自然的首选程序是以下非常复杂的代码:

#include <iostream>
using std::cout;    using std::endl;
/* hello world.cpp */
int main()
{
    cout << "Hello, world!" << endl;
    return 0;
}

在命令行上我做了:clang helloworld.cpp我收到以下错误信息:

Undefined symbols for architecture x86_64:
  "std::ios_base::Init::~Init()", referenced from:
      ___cxx_global_var_init in cc-4iziZq.o
  "std::ios_base::Init::Init()", referenced from:
      ___cxx_global_var_init in cc-4iziZq.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 cc-4iziZq.o
  "std::cout", referenced from:
      _main in cc-4iziZq.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 cc-4iziZq.o
  "std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
      _main in cc-4iziZq.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有什么问题? 谢谢! -kstruct

2 个答案:

答案 0 :(得分:19)

clang是一个C编译器。您需要使用clang++或使用-x c++标记。

答案 1 :(得分:4)

  

clang是一个C编译器。您需要使用clang ++或使用-x c ++标志。

仍然需要添加 -lstdc ++

我通过 -v 选项找出了这一点。我发现差异是:

铛++

  

-lstdc ++   -lm   -lgcc_s   -lgcc   -lc   -lgcc_s   -lgcc

  

-lgcc    - 如所须   -lgcc_s   --no-按需   -lc   -lgcc    - 如所须   -lgcc_s   --no-按需