Re: Using the -l option

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

 



carterp@xxxxxxxxxxxxx writes:

> I was trying to compile a program that used a function from math.h and couldn't
> get it to work, until I found out that I needed to use "gcc -lm test.c", and
> #include <math.h> in the program wasn't enough.  I know from the documentation
> that -lxxxx searches the library named xxxx when linking, but how do I know
> what library to name?  I wouldn't have guessed that I need -lm when I'm using
> math.h, and I'm wondering what the chances are that I'll run into this problem
> again when I need some other library.  I'm also using time.h in a program, but
> I only needed to use an #include statement, with nothing extra on the command
> line.

This is not actually a gcc issue.  It is a library issue.

Normally the documentation for the library will tell you which
libraries you need to link against.  For example, on NetBSD, "man
sqrt" starts with
    LIBRARY
         Math Library (libm, -lm)

Unfortunately, the man pages for the math functions on GNU/Linux don't
seem to say this (at least not on Fedora Core 4).  Ideally that would
be fixed in the library documentation.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux