从Mac上的终端编译时C 错误

c++ error when compiling from terminal on mac

本文关键字:错误 编译 终端 Mac      更新时间:2023-10-16

尝试使用该程序编译我的程序称为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 而不是C 项目的GCC。另外,将std添加到getline中,为std::getline