Re: sinf compiler error I don't understand (corrected)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01Apr2011 15:46, les <hlhowell@xxxxxxxxxxx> 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\n",M_PI);
| >     printf ("sin 90 = %e\n",sinf(M_PI/2));
| >     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\n",sinf(temp));
| > }
| > 
| > 
| > 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@xxxxxxxxxxxxxxxxxxxxx> 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.

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

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

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux