[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: Undefined reference in C

Hi Marie,

you also need to make the appropriate libraries available.
Include files only contain the prototypes and structures necessary
to use the functions; for example for sin(), you need the math library
(usually something like libm.so, assuming you are on a Unix system)
which contains the real implementation of the functions.
I dont currently have my Eclipse installation with CDT available, but
there must be an entry somewhere below Project Properties where you can
add libraries. At least, the linker needs to retrieve an option such
as "-lm" to link against the math library (the lib prefix and the .so suffix
are added automatically).

Best Regards,

        Andreas

Marie Tessier wrote:

> I am using the CDT plugin that lets me use C in Eclipse.  I am having one
> error though, and it is driving me nuts because I can't find the exact
> answer on google.  I am using just one c file, Doodle.c, and here is the
> beginning of it:
> 
> #include <GL/glut.h>
> #include <math.h>
> #include "Doodle.h"
> 
> const double pi2 = 6.28318530718;
> 
> void NonlinearMap(double *x, double *y) {
>     static double K = 1.04275;
>     *y += K * sin(*x);    // (1)
>     *x += *y;
>     *x = fmod(*x, pi2);    // (2)
>     if (*x < 0.0) {
>         *x += pi2;
>     };
> };
> ..
> (there is more to it than this, but this shows plenty).
> 
> On the line marked (1), I get the error "Undefined reference to 'sin'".
> Now this is surprising, because I have the #include <math.h>.  Eclipse
> even has math.h listed in the Outline pane, and I can double click it and
> math.h opens up.  An odd thing is that I cannot find any reference to a
> sin function in that file.  I have exactly the same problem with fmod on
> the line marked (2).  I have identical errors involving anything having to
> do with GL/glut.h, also included above (same ability to open glut, same
> inability to find any reference to the involved functions in it).  I am
> reasonably confident of the code because it is example code from a
> website.  Help!  I am so clueless!
> 
> Marie