GCC problem - math.h included, but fmod not available
I wrote a program to test my understanding of fmod:
#include
On Sunday 08 January 2006 06:10, Shriramana Sharma wrote:
I wrote a program to test my understanding of fmod:
#include
#include int main(void) { double a = 259192.42201; double b = 24.10501259; printf("%11.10f", fmod(a,b)); }
but I get the error:
samjnaa@linux:~/bin/learning> gcc fmod.c -o fmod /tmp/ccK9XIYg.o: In function `main': fmod.c.text+0x49): undefined reference to `fmod' collect2: ld returned 1 exit status
When you compile things that need libm you also need to link against libm gcc -o fmod -lm fmod.c The -lm links in libm and gives you access to the mathematical functions in it. This is also mentioned in "man fmod"
Sunday, 08 January 2006 10:53 samaye, Anders Johansson alekhiit:
When you compile things that need libm you also need to link against libm
What is libm please? I see that it is something that glibc provides.
it. This is also mentioned in "man fmod"
Hey great! I didn't know I have a C reference library among the man pages. Didn't strike me to try that! :) -- Penguin #395953 resides at http://samvit.org subsisting on SUSE Linux 10.0 with KDE 3.5
On 1/8/06, Shriramana Sharma
Sunday, 08 January 2006 10:53 samaye, Anders Johansson alekhiit:
When you compile things that need libm you also need to link against libm
What is libm please? I see that it is something that glibc provides.
libm is the name of the math library located in /usr/lib. The -l switch tells gcc to link against the specified library. Normally, the lib* prefix is omitted here just as seen with linking against 'libpthread' by specifying 'lpthread'.
it. This is also mentioned in "man fmod"
Hey great! I didn't know I have a C reference library among the man pages. Didn't strike me to try that! :)
Effectively all UNIX systems come with manpages for system calls and
library functions (commonly sections 2 and 3).
\Steve
--
Steve Graegert
Sunday, 08 January 2006 13:41 samaye, Steve Graegert alekhiit:
libm is the name of the math library located in /usr/lib. The -l switch tells gcc to link against the specified library. Normally, the lib* prefix is omitted here just as seen with linking against 'libpthread' by specifying 'lpthread'.
So do I need to specify -lt if I want to link against time.h? There are fifteen ANSI libraries - assert, ctype, errno, float, limits, locale, math, setjmp, signal, stdarg, stddef, stdio, stdlib, string, time. Do I do a -l for each of these?
Effectively all UNIX systems come with manpages for system calls and library functions (commonly sections 2 and 3).
System calls such as? chmod? -- Penguin #395953 resides at http://samvit.org subsisting on SUSE Linux 10.0 with KDE 3.5
Shriramana Sharma wrote:
libm is the name of the math library located in /usr/lib. The -l switch tells gcc to link against the specified library. Normally, the lib* prefix is omitted here just as seen with linking against 'libpthread' by specifying 'lpthread'.
So do I need to specify -lt if I want to link against time.h?
No, the functions define in time.h are included in the default libraries.
There are fifteen ANSI libraries - assert, ctype, errno, float, limits, locale, math, setjmp, signal, stdarg, stddef, stdio, stdlib, string, time. Do I do a -l for each of these?
Those are include files, not libraries. And no, you don't need to add -l for each of those.
Effectively all UNIX systems come with manpages for system calls and library functions (commonly sections 2 and 3).
System calls such as? chmod?
For instance, yes. "man 2 chmod" /Per Jessen, Zürich
Sunday, 08 January 2006 15:34 samaye, Per Jessen alekhiit:
No, the functions define in time.h are included in the default libraries.
So how do I find out which functions defined in which standard headers are included in the default libraries and which not?
There are fifteen ANSI libraries - assert, ctype, errno, float, limits, locale, math, setjmp, signal, stdarg, stddef, stdio, stdlib, string, time. Do I do a -l for each of these?
Those are include files, not libraries. And no, you don't need to add -l for each of those.
You mean I can add a single -l for all of them? I'm sorry I'm confused. Please explain. IIRC include files are declarations of functions available in libraries. If there are fifteen standard include files, why are the corresponding libraries not included by default? Is the compiler is going to stuff into the final executable file *all* the functions (including unused) present in the libraries? -- Penguin #395953 resides at http://samvit.org subsisting on SUSE Linux 10.0 with KDE 3.5
Shriramana, Once again, you're looking for tutorial information. And it's about programming in C in a Unix / POSIX / Linux environment. It's at best tangentially relevant to the SuSE-Linux-E charter. Better would be SuSE-Programming-E, but I think that if you're going to embark on C programming, which gets pretty arcane pretty quickly, that you should find a coherent tutorial course, either a book or two or on a Web site specifically designed to teach C programming ab inito. Peppering people on mailing lists with questions about every little roadblock you hit annoys the list denizens and does nothing to enhance your ability to function autonomously. Randall Schulz On Sunday 08 January 2006 17:42, Shriramana Sharma wrote:
...
So how do I find out which functions defined in which standard headers are included in the default libraries and which not?
...
Monday, 09 January 2006 09:12 samaye, Randall R Schulz alekhiit:
tangentially relevant to the SuSE-Linux-E charter.
It started out as what I thought was a GCC problem. Apologies if I annoyed anyone. -- Penguin #395953 resides at http://samvit.org subsisting on SUSE Linux 10.0 with KDE 3.5
Shriramana Sharma wrote:
Sunday, 08 January 2006 15:34 samaye, Per Jessen alekhiit:
No, the functions define in time.h are included in the default libraries.
So how do I find out which functions defined in which standard headers are included in the default libraries and which not?
I'm sure there is a library reference somewhere, but trial-and-error will tell you too.
There are fifteen ANSI libraries - assert, ctype, errno, float, limits, locale, math, setjmp, signal, stdarg, stddef, stdio, stdlib, string, time. Do I do a -l for each of these?
Those are include files, not libraries. And no, you don't need to add -l for each of those.
You mean I can add a single -l for all of them? I'm sorry I'm confused. Please explain.
No, they are header files and except for math, the corresponding library is included by default. So no need to add any '-l' except for math.
IIRC include files are declarations of functions available in libraries. If there are fifteen standard include files, why are the corresponding libraries not included by default?
The default library is. But your questions are probably better asked elsewhere - like Randall Schultz also suggested. Especially if you want to know about why and how the compiler does what it does, the gnu-gcc lists might be a good suggestion. /Per Jessen, Zürich -- http://www.spamchek.com/ - managed anti-spam and anti-virus solution. Let us analyse your spam- and virus-threat - up to 2 months for free.
participants (5)
-
Anders Johansson
-
Per Jessen
-
Randall R Schulz
-
Shriramana Sharma
-
Steve Graegert