c++ - 体系结构 x86_64 Xcode Mac 的 undefined symbol

标签 c++ undefined symbols

我需要一些帮助。 最近想学编程,遇到了一些问题,不过都解决了。 除了这个。 我知道已经回答了很多次,但我从未找到针对我的具体案例的解决方案。 我正在使用 Xcode V.4.5.2 这是程序:

int add(int x, int y);

int main()

    using namespace std;
    cout << "3 + 4 + 5 = " << add(3, 4) << endl;
    return 0;
}

int add(int x, int y, int z)

    return x + y + z;
}

它给我这个错误:

Undefined symbols for architecture x86_64: "add(int, int)", referenced from: _main in main.o (maybe you meant: __Z3addiii) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

我不知道该怎么办。

我一直在学习这个教程:

http://www.learncpp.com/cpp-tutorial/17-forward-declarations/

Quiz下的第五个程序就是这个。

谢谢 柠檬水

最佳答案

您的前向声明是 int add(int x, int y); 但您的定义是 int add(int x, int y, int z)。第一个没有 int z 但第二个有。他们需要匹配 100%。定义大概应该是:

int add(int x, int y) {
    return x + y;
}

链接器错误告诉您“我不知道任何 add(int, int) 函数”,这是恰当的,因为没有任何类型的 add 定义(int, int) 函数。只有一个 add(int, int, int) 函数,这显然是不同的。

关于c++ - 体系结构 x86_64 Xcode Mac 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15012917/

上一篇:c++ - 计划的目的

下一篇:C++ 模板优化

相关文章:

c++ - 在没有 typedef 的情况下使用时显示编译错误的函数的 volatile 指针;需要帮助 w/"void (* volatile userFunc)(void)"

c++ - OpenGL 纹理的 OpenCV 图像加载

testing - VHDL testbench 在仿真波形中获取 U

javascript - 无法访问 Javascript 数组中的变量。 Console.log 说未定义

javascript - 在 Javascript 中测试未定义的函数

elf - 在 ELF 文件中,如何确定 _start 的地址?

c++ - 判断变量是否为指针的宏

golang 从控制台删除符号

c++ - 当提供 windows .dmp 或 .minidmp 时,您如何识别(并访问)要使用的模块/调试符号

.net - 在 C++\Win32 中编辑控件文本更改消息