Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Undefined reference in C
Undefined reference in C [message #52901] Sun, 17 April 2005 00:08 Go to next message
Eclipse UserFriend
Originally posted by: marie.u.washington.edu

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
Re: Undefined reference in C [message #53105 is a reply to message #52901] Sun, 17 April 2005 11:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Andreas.Fester.agile.com

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
Re: Undefined reference in C [message #53206 is a reply to message #53105] Sun, 17 April 2005 17:43 Go to previous message
Eclipse UserFriend
Originally posted by: marie.u.washington.edu

Thank you, that helped some and it gave me some more search terms for
google. I came up with this:

"I fixed my problem. I had to include every source folder in the project
paths source tab (Properties --> C/C++ Project Paths --> Source). Once I
had my Source option set up correctly the auto discovery found all my
libraries. This is cool. Now I can do my Java and C programming all in
one IDE. The C plugin has a mere fraction of what I have in Java for IDE
functionality, but I guess its enough. I can even run the project from
within Eclipse now."

This persion's problem was that he could not figure out how to add
things to the blue 'Includes' folder, which I see in my system does not
have '/usr/lib' in it. This is of course a problem because that appears
to be a large repository of libraries on my computer. So this snippet of
help is really cool except that there is no 'C/C++ Project Paths'
section in the Properties box in my Eclipse, which is 3.0.2. Perhaps
this was in a previous version. How do I do this in my version?

On a note to the development team, it could be easier to add paths to
the includes section, maybe add it to a properties option accessible by
right clicking on the includes folder in the file tree.

Marie Tessier


Andreas Fester wrote:
> 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
>
>
Previous Topic:creating markers
Next Topic:Java Import
Goto Forum:
  


Current Time: Sat Aug 10 07:50:58 GMT 2024

Powered by FUDForum. Page generated in 0.09360 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top