【问题标题】:c++ error when compiling from terminal on mac在mac上从终端编译时出现c++错误
【发布时间】:2017-09-30 14:53:21
【问题描述】:

尝试使用以下命令编译我的名为 main.cpp 的程序 gcc main.cpp 使用终端在我的 Mac 上编译的命令。我收到以下错误

undefined symbols for architecture x86_64:
  "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
      _main in main-db0d6c.o
. . . 
Dwarf Exception Unwind Info (__eh_frame) in main-db0d6c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是程序:

// Example program
#include <iostream>
#include <string>

int main()
{
   std::string name;
   std::cout << "What is your name? ";
   getline (std::cin, name);
   std::cout << "Hello, " << name << "!\n";
}

非常感谢任何帮助,甚至为我指明正确的方向。我不明白如何阅读此错误消息,并且想学习并让我的基本程序运行。

【问题讨论】:

  • 你能显示你用来编译这个的命令吗?
  • 使用 g++ gcc.
  • @InternetAussie,OP 说 使用 gcc main.cpp 调用 main.cpp
  • facepalm 我错过了

标签: c++ macos terminal


【解决方案1】:

在 c++ 项目中使用 g++ 而不是 gcc。另外,将std 添加到getlinestd::getline

【讨论】:

    猜你喜欢
    • 2017-06-09
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    相关资源
    最近更新 更多