-3

I'm new to C++, and I attempted to compile a program when I received the error message

undefined reference to '(lengthy void function name)'

After reading around a bit, I think my program has what is called a linker error (correct me if I'm wrong). I am not using any headers in this program, and my function prototype, function call (in main), and my function definition all have the same variables within the parenthesis. I was under the impression that these errors mainly result from typos, but after poring over the code, I don't think that's the case here. What are the other causes of linker errors (in terms a newbie could understand, please)?

Alex Celeste
  • 12,824
  • 10
  • 46
  • 89
Halp
  • 1
  • 3
    If you post your code, you are more likely to get help. – R Sahu Sep 11 '14 at 00:12
  • If you are programming in c++, then typos should typically result in compiler errors and not linker errors. Linker errors are mostly caused by not linking to the correct libraries/object-files or forgetting to implement the specific functions. – youdontneedtothankme Sep 11 '14 at 00:21
  • It generally means you either misspelled `length` `lengthy` somewhere in your code, or you are using a function say `lengthy (foo)` and you either haven't included the header, are using it before it is defined, forgot to link the library or your forgot to define `lengthy (foo)` altogether. – David C. Rankin Sep 11 '14 at 00:22
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Niall Sep 11 '14 at 08:19
  • I apologize for my lack of correct formatting, but thanks to those of you who provided input. The problem is now resolved. – Halp Sep 11 '14 at 19:54

1 Answers1

0

Without your code, it's almost impossible to tell what the problem could be, however, if I had to guess, it's possible you defined your function after main, and so main can't access it. Eg:

int main()
{
    //Call to lengthy void function
}

void lengthyFunction()
{
    //code
}

just cut and paste your function definition to before main:

void lengthyFunction()
{
    //code
}

int main()
{
    //call to lengthy void function
}
Shadow
  • 3,926
  • 5
  • 20
  • 41