I tried compiling a C++ program only to get a cryptic error similar to “symbols not found for architecture x86_64.” Thanks, g++, for not making any sense.
The problem was that I had a prototype declared in a global scope like:
//#include stuff here// This is a function "prototype"// Make the existence of badFunctionName() known to the rest of the program.void badFunctionName();int main(){ // Let's use our new function badFunctionName(); return 0;}
The implementation of that function badFunctionName()
was below main()
like so:
void badFuntionName(){ // Cool stuff here.}
You probably already caught the spelling error for this simple example; but imagine that typo in a slightly larger program with more functions. The function name that was declared in the prototype was badFunctionName()
but the function implemented was badFuntionName()
. Now, you’d hope that the compiler would tell you that you can’t spell and suggest a fix. Unfortunately, it’ll only say “symbols not found for architecture x86_64.”
Syntactically speaking, there’s nothing wrong with the code. Even with the typo, you’re still declaring a valid function. You’re not really using the incorrect badFuntionName()
function since we called the desired function in main()
; so you won’t get compiler errors about badFuntionName()
not being defined before the reference.
What I mean by that is that if you call/reference a function that hasn’t been defined (or its prototype hasn’t been included in a global scope), the compiler will complain that it doesn’t know of the function you’re using. With that said, we’re not actually calling the incorrect badFuntionName()
function, so we don’t get that aforementioned clue from the compiler.
The fix, of course, is ultra-trivial: spell the damn function correctly!