C++ on Xcode 7.01 on El Capitan Error -> Undefined symbols for architecture x86_64:

C++ on Xcode 7.01 on El Capitan Error -> Undefined symbols for architecture x86_64:

Undefined symbols for architecture x86_64:
  "makeHero(std::string, int)", referenced from:
   makeCard() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是我在 Xcode 上尝试编译代码时遇到的错误。我环顾四周,将架构设置更改为通用,并创建了 C++ 标准库 libstdc++,这是我在此处找到的答案。仍然没有:/

 #include <iostream>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string>

using namespace std;

我的 main.cpp 文件的开头是什么原因造成的?我将 stdlib.h 和 stdio.h 更改为没有 .h 并且我找不到 stdlib 文件。

Undefined symbols for architecture x86_64

这个错误消息相当具有误导性,它真正告诉你的是编译器已经看到 makeHero(std::string, int) 的函数声明(符号),但找不到它的实现。

通过在头文件中声明一个函数,无需在头文件或 cpp 中实现函数体,即可轻松重现该错误。

要解决此问题,请确保该函数的主体已在项目中实现。