Question

After hours and hours of working on a program, and eliminating all the syntax errors, I came across this error which I have no idea what is or why it there. This is the error:

/tmp/ccKnig3z.o: In function `main':
line_formula_convert.c:(.text+0x113): undefined reference to `intcp_from_pt_slope'
collect2: error: ld returned 1 exit status


Here's the whole program, if it is of any help for you. http://pastebin.com/9CNsaaF0
I am using Fedora 19, and gcc -Wall in compiling my program. Any help explaining this error is appreciated, and I am sorry if this is an elementary question.

Was it helpful?

Solution

Alright now we are talking, after you've posted the link for your code.

void incp_from_pt_slope(double x1, double y1, double m, double *b) ;
       |
void intcp_from_pt_slope(double x1, double y1, double m, double *b);

Did you see difference ? incp_from_pt_slope is not same as incp_from_pt_slope, and that's why linker complains that undefined reference error.

OTHER TIPS

  1. Use #include for the declaration
  2. Use -l option to link to the library
  3. Read the manual page for the compiler

You have a call in your code to a function called intcp_from_pt_slope which is not defined anywhere. The error occurs from the linker. Each module of your program is compiled separately and you use prototypes to declare functions that may exist in separate compilation units (.c files). The linker then takes all the object files and resolves all the functions so that every function is pointing to something that has been given an implementation. If it cannot find an implementation for a function, you get the error you have reported. This may be because you missed an object from the linker command line, or you just typed the name incorrectly.

It is probably a typo and you need a space between the int and cp_from_pt_slope.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top