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

标签 c++ xcode macos osx-elcapitan

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 中实现函数主体,即可轻松重现该错误。

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

关于C++ on Xcode 7.01 on El Capitan Error -> Undefined symbols for architecture x86_64 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33272965/

相关文章:

c++ - Model/View Qt文档中关于排序的描述可能有误?

c++ - LNK2019 - 未解析的外部符号 C++

c# - 将非托管类型结构指针转换为托管类型结构指针

c++ - (C++) 在构造函数中初始化的变量被放在一个无关数组的末尾。

ios - 使用图像快速更改页面控制点

swift - 为 shell 命令获取实用程序的完整路径,如 7zip 等

iPhone编程: avaudioplayer leaks memory on play

iphone - 需要帮助了解我在我的第一个 iPhone 应用程序上出现的错误

ruby-on-rails - Sunspot not working with You need a Java Runtime Environment to run the Solr serve 错误

ios - Swift 结构中的内存泄漏 - 如何解决这个问题?