FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.

» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

LinkBack Thread Tools
Old 04-02-2011, 12:03 AM
Cameron Simpson
Default sinf compiler error I don't understand (corrected)

On 01Apr2011 15:46, les <hlhowell@pacbell.net> wrote:
| > Here is the smallest sample I have been working with to show the current
| > error:
| >
| > #include <math.h>
| > main()
| > {
| > long double temp;
| > printf ("M_PI=%e
| > printf ("sin 90 = %e
| > temp=M_PI/2.0;
| > // the following line won't compile for temp
| > // regardless of how temp is declared (float, double, long double)
| > // printf ("sin 90 = %e
| > }
| >
| >
| > Clearly sinf is recognized, and compiles and runs. It returns 1.000 as
| > expected for M_PI/2. But the line that is commented out will not
| > compile.
| missing command and error message:
| gcc -ggdb mathck.c
| /tmp/ccTdnf1Z.o: In function `main':
| /home/lesh/Code/C/arb_wav_file/mathck.c:14: undefined reference to
| `sinf'
| collect2: ld returned 1 exit status

As Michael Hennebry <hennebry@web.cs.ndsu.nodak.edu> said, you need to
-lm option. To be explicit, since Michael was not, this:

gcc mathck.c -lm

Including math.h makes various symbolc and function signatures (type and
args) known to the compiler, letting you generate a call to sinf().

However, the math library is not part of the standard C library, so you
need to add it in the link phase so the the code implementing sinf() is
available. Note that it comes after the course files because linking is
an ordered process: the symbol "sinf" from you code needs to be seen and
wanted before the math library is consulted; "-lm" is just shorthand for
the path to the math shared library.

Cameron Simpson <cs@zip.com.au> DoD#743

network security: 1. Kill all your users.
2. Remove all accounts.
3. Detach network and dialups.
4. Turn off machine.
- David A. Guidry <empire@nwu.edu>
users mailing list
To unsubscribe or change subscription options:
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

Thread Tools

All times are GMT. The time now is 10:31 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org