Reputation: 83
I need some help. Recently I've tried to learn some programming, and had a couple of problems, but they've all been solved. except for this one. I know it has been answered many times, but I have never found a solution for my specific case. I am using Xcode V. 4.5.2 Here is the program:
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;
}
It gives me this error:
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)
I have no idea what to do.
I have been following this tutorial:
http://www.learncpp.com/cpp-tutorial/17-forward-declarations/
the Fifth Program under Quiz is this one.
Thanks Lemonizer
Upvotes: 0
Views: 3510
Reputation: 38217
Your forward declaration is int add(int x, int y);
but your definition is int add(int x, int y, int z)
. The first one has no int z
but the second one does. They need to match 100%. The definition should probably be:
int add(int x, int y) {
return x + y;
}
That linker error is telling you "I don't know of any add(int, int)
functions," which is appropriate, because there is no definition for any kind of add(int, int)
function. There's only an add(int, int, int)
function, which is, obviously, different.
Upvotes: 1