目标任务/场景: mac 下面编译运行 C++ 代码, 出错: Undefined symbols for architecture x86_64
Mac 下面, 创建文件 hello.cpp
#include <iostream>
using namespace std;
int main(){
int i =5;
int b =0;
if(i>2){
b = i*i;
}
std::cout << b << endl;
return 0;
}
运行 gcc hello.cpp , 报错提示: Undefined symbols for architecture x86_64
解决方案: 使用标准库来编译
gcc hello.cpp -o hello -lstdc++
./hello