use of long double

Discussion in 'C Programming' started by Ryan Lee, Oct 7, 2003.

  1. Ryan Lee

    Ryan Lee Guest

    How to use math functions of type long double in gcc? I used powl and expl
    in my source code (and included math.h) but I got "undefined reference to
    `_powl'" when I tried to compile it with:

    gcc -o 1_1prog 1_1prog.c -lm

    I also tried "-ansi" and "-std=c99" but still got the same message. Does
    anyone have any idea?

    Thanks a lot!

    Ryan
    Ryan Lee, Oct 7, 2003
    #1
    1. Advertising

  2. Ryan Lee

    Tim Prince Guest

    Ryan Lee wrote:

    > How to use math functions of type long double in gcc? I used powl and expl
    > in my source code (and included math.h) but I got "undefined reference to
    > `_powl'" when I tried to compile it with:
    >
    > gcc -o 1_1prog 1_1prog.c -lm
    >
    > I also tried "-ansi" and "-std=c99" but still got the same message. Does
    > anyone have any idea?
    >
    > Thanks a lot!
    >
    > Ryan

    powl() is provided (or not) by the libm installed on your system. If your
    library doesn't include it, you must provide it yourself (and add the
    prototypes to <math.h>). It's not too difficult to write for i386
    processors. expl() could be provided with a <mathinline.h> for such
    processors. -ansi probably means C89, where provision of long double math
    functions is optional, and varies by platform. These options don't cause
    gcc to change its selection of libraries, or go out looking on the Internet
    for something matching your desire.
    --
    Tim Prince
    Tim Prince, Oct 8, 2003
    #2
    1. Advertising

  3. Ryan Lee

    Richard Bos Guest

    Tim Prince <> wrote:

    > Ryan Lee wrote:
    >
    > > How to use math functions of type long double in gcc? I used powl and expl
    > > in my source code (and included math.h) but I got "undefined reference to
    > > `_powl'" when I tried to compile it with:
    > >
    > > gcc -o 1_1prog 1_1prog.c -lm
    > >
    > > I also tried "-ansi" and "-std=c99" but still got the same message. Does
    > > anyone have any idea?

    >
    > powl() is provided (or not) by the libm installed on your system.


    In C99, it must be present. In C89, it isn't allowed to be (or at least,
    not when you ask for ISO C mode).

    If GCC and its libs don't provide powl() even in C99 mode, they may be
    incomplete. Ask in a Gnu group whether there is a version that does
    provide the C99 math functions, or whether you need to invoke GCC some
    other way.

    > If your library doesn't include it, you must provide it yourself (and
    > add the prototypes to <math.h>).


    It is never wise to muck about with the system header files. Write your
    own additional header.

    > It's not too difficult to write for i386
    > processors. expl() could be provided with a <mathinline.h>


    By _what_? That's not an ISO C header.

    Richard
    Richard Bos, Oct 8, 2003
    #3
  4. Richard Bos <> wrote:
    > Tim Prince <> wrote:
    >
    >> Ryan Lee wrote:
    >>
    >> > How to use math functions of type long double in gcc? I used powl and expl
    >> > in my source code (and included math.h) but I got "undefined reference to
    >> > `_powl'" when I tried to compile it with:
    >> >
    >> > gcc -o 1_1prog 1_1prog.c -lm
    >> >
    >> > I also tried "-ansi" and "-std=c99" but still got the same message. Does
    >> > anyone have any idea?

    >>
    >> powl() is provided (or not) by the libm installed on your system.


    Correct.

    >
    > In C99, it must be present. In C89, it isn't allowed to be (or at least,
    > not when you ask for ISO C mode).


    True for hosted compilers. False for freestanding compilers.

    >
    > If GCC and its libs don't provide powl() even in C99 mode, they may be
    > incomplete. Ask in a Gnu group whether there is a version that does
    > provide the C99 math functions, or whether you need to invoke GCC some
    > other way.


    GCC itself is just a freestanding compiler, and thus does not include
    any math libraries (and very few other libraries either.)
    GCC uses whatever libraries are available on the host, so it is the
    people who provide those one must speak to (or install some suitable
    third-party implementation of the libraries yourself.)

    --
    <Insert your favourite quote here.>
    Erik Trulsson
    Erik Trulsson, Oct 8, 2003
    #4
  5. Ryan Lee

    Richard Bos Guest

    Erik Trulsson <> wrote:

    > Richard Bos <> wrote:
    > > If GCC and its libs don't provide powl() even in C99 mode, they may be
    > > incomplete. Ask in a Gnu group whether there is a version that does
    > > provide the C99 math functions, or whether you need to invoke GCC some
    > > other way.

    >
    > GCC itself is just a freestanding compiler, and thus does not include
    > any math libraries (and very few other libraries either.)
    > GCC uses whatever libraries are available on the host, so it is the
    > people who provide those one must speak to (or install some suitable
    > third-party implementation of the libraries yourself.)


    Yes, that's the Gnu party line, but I've never seen GCC without GLib.

    Richard
    Richard Bos, Oct 8, 2003
    #5
  6. Ryan Lee

    Dan Pop Guest

    In <> (Richard Bos) writes:

    >Tim Prince <> wrote:
    >
    >> Ryan Lee wrote:
    >>
    >> > How to use math functions of type long double in gcc? I used powl and expl
    >> > in my source code (and included math.h) but I got "undefined reference to
    >> > `_powl'" when I tried to compile it with:
    >> >
    >> > gcc -o 1_1prog 1_1prog.c -lm
    >> >
    >> > I also tried "-ansi" and "-std=c99" but still got the same message. Does
    >> > anyone have any idea?

    >>
    >> powl() is provided (or not) by the libm installed on your system.

    >
    >In C99, it must be present. In C89, it isn't allowed to be (or at least,
    >not when you ask for ISO C mode).


    However, this is a library issue and gcc is merely a compiler.

    >If GCC and its libs don't provide powl() even in C99 mode, they may be


    gcc and its libs (i.e. libgcc.a) are not supposed to provide powl() in
    *any* mode.

    >incomplete. Ask in a Gnu group whether there is a version that does
    >provide the C99 math functions, or whether you need to invoke GCC some
    >other way.


    gcc is using whatever implementation of the standard library is available
    on the system, which need not have anything to do with any GNU project.
    Please don't post bogus advice!

    >> If your library doesn't include it, you must provide it yourself (and
    >> add the prototypes to <math.h>).

    >
    >It is never wise to muck about with the system header files. Write your
    >own additional header.
    >
    >> It's not too difficult to write for i386
    >> processors. expl() could be provided with a <mathinline.h>

    >
    >By _what_? That's not an ISO C header.


    So what? No ANSI C89 standard header is allowed to declare expl(), so
    the declaration/definition must come from some other header. If the OP
    had a C99-conforming standard library implementation, he wouldn't have
    posted the question in the first place.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Oct 8, 2003
    #6
  7. Ryan Lee

    Dan Pop Guest

    In <blunt4$iit$> "Ryan Lee" <> writes:

    >How to use math functions of type long double in gcc? I used powl and expl
    >in my source code (and included math.h) but I got "undefined reference to
    >`_powl'" when I tried to compile it with:
    >
    >gcc -o 1_1prog 1_1prog.c -lm
    >
    >I also tried "-ansi" and "-std=c99" but still got the same message. Does
    >anyone have any idea?


    Try to engage your brain. If you're not Mark McIntyre, it usually helps.

    gcc is a *compiler*. Math functions are a *library* issue, and,
    therefore, their usage has precious little to do with gcc. The best you
    can do at gcc invocation level is to specify -std=c99 if you need
    functions that are new in C99 and hope that this will enable their
    declarations in <math.h>, if such functions are present at all in your
    libraries. But this has absolutely no effect on whether the linker will
    or will not find them in the actual libraries. However, if you also use
    -Wall, you'll know, at least, whether declarations for the functions in
    question have been found in <math.h> or not (you'll get warnings for
    each function that is called without a declaration in scope).

    Your experiment has clearly shown that there is no such thing as powl in
    your libm library. There is absolutely nothing gcc can do about this!
    And, since we don't know what system and what libraries you're using,
    there is no way we can provide a solution (other than advise to write
    your own versions of the missing functions).

    You may get better advice in a newsgroup dedicated to programming on your
    platform, especially if you mention what libraries you have installed
    on your machine (again: it's a library issue, not a gcc issue).

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Oct 8, 2003
    #7
  8. Ryan Lee

    Tim Prince Guest

    Richard Bos wrote:

    > Erik Trulsson <> wrote:
    >
    >> Richard Bos <> wrote:
    >> > If GCC and its libs don't provide powl() even in C99 mode, they may be
    >> > incomplete. Ask in a Gnu group whether there is a version that does
    >> > provide the C99 math functions, or whether you need to invoke GCC some
    >> > other way.

    >>
    >> GCC itself is just a freestanding compiler, and thus does not include
    >> any math libraries (and very few other libraries either.)
    >> GCC uses whatever libraries are available on the host, so it is the
    >> people who provide those one must speak to (or install some suitable
    >> third-party implementation of the libraries yourself.)

    >
    > Yes, that's the Gnu party line, but I've never seen GCC without GLib.
    >
    > Richard

    OP must be using gcc without glibc, or the question would not have arisen.
    I have used implementations of gcc on 2 systems with hardware but no
    math library support for long double: Irix and cygwin. On Irix, gcc
    supported long double only as a synonym for double. On cygwin, the lack of
    library support makes long double non-conformant with either C89 or C99.
    --
    Tim Prince
    Tim Prince, Oct 8, 2003
    #8
  9. Ryan Lee

    Dan Pop Guest

    In <> (Richard Bos) writes:

    >Erik Trulsson <> wrote:
    >
    >> Richard Bos <> wrote:
    >> > If GCC and its libs don't provide powl() even in C99 mode, they may be
    >> > incomplete. Ask in a Gnu group whether there is a version that does
    >> > provide the C99 math functions, or whether you need to invoke GCC some
    >> > other way.

    >>
    >> GCC itself is just a freestanding compiler, and thus does not include
    >> any math libraries (and very few other libraries either.)
    >> GCC uses whatever libraries are available on the host, so it is the
    >> people who provide those one must speak to (or install some suitable
    >> third-party implementation of the libraries yourself.)

    >
    >Yes, that's the Gnu party line, but I've never seen GCC without GLib.


    You haven't looked hard enough! glibc2 is supported *only* on Hurd and
    Linux, while gcc covers an extremely wide range of platforms. glibc1
    was virtually unused, due to the lack of support for dynamic linking.

    It is the support for dynamic linking that makes glibc2 so hard to port
    that nobody bothered to do it on platforms that already had their shared
    libraries. Even porting it to Linux on a new hardware platform is
    something not recommended to the faint of heart.

    It is, therefore, not uncommon to see gcc accompanied by ad hoc
    implemented libraries on platforms that don't already provide C libraries,
    e.g. DJGPP for extended MSDOS.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Oct 8, 2003
    #9
  10. Ryan Lee

    CBFalconer Guest

    Richard Bos wrote:
    > Erik Trulsson <> wrote:
    > > Richard Bos <> wrote:

    >
    > > > If GCC and its libs don't provide powl() even in C99 mode,
    > > > they may be incomplete. Ask in a Gnu group whether there is
    > > > a version that does provide the C99 math functions, or
    > > > whether you need to invoke GCC some other way.

    > >
    > > GCC itself is just a freestanding compiler, and thus does not
    > > include any math libraries (and very few other libraries
    > > either.) GCC uses whatever libraries are available on the
    > > host, so it is the people who provide those one must speak
    > > to (or install some suitable third-party implementation of
    > > the libraries yourself.)

    >
    > Yes, that's the Gnu party line, but I've never seen GCC
    > without GLib.


    I believe both Cygwin and DJGPP provide independant libraries.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
    CBFalconer, Oct 8, 2003
    #10
  11. Ryan Lee

    Dan Pop Guest

    In <> CBFalconer <> writes:

    >Richard Bos wrote:
    >> Erik Trulsson <> wrote:
    >> > Richard Bos <> wrote:

    >>
    >> > > If GCC and its libs don't provide powl() even in C99 mode,
    >> > > they may be incomplete. Ask in a Gnu group whether there is
    >> > > a version that does provide the C99 math functions, or
    >> > > whether you need to invoke GCC some other way.
    >> >
    >> > GCC itself is just a freestanding compiler, and thus does not
    >> > include any math libraries (and very few other libraries
    >> > either.) GCC uses whatever libraries are available on the
    >> > host, so it is the people who provide those one must speak
    >> > to (or install some suitable third-party implementation of
    >> > the libraries yourself.)

    >>
    >> Yes, that's the Gnu party line, but I've never seen GCC
    >> without GLib.

    >
    >I believe both Cygwin and DJGPP provide independant libraries.


    They have to, glibc being an implementation of the standard Unix
    library, it's not that feasible to port it to a non-Unix platform, even
    if one ignores the dynamic linking support issues I've mentioned in
    another post.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Oct 8, 2003
    #11
  12. Ryan Lee

    Richard Bos Guest

    CBFalconer <> wrote:

    > Richard Bos wrote:
    > > Yes, that's the Gnu party line, but I've never seen GCC
    > > without GLib.

    >
    > I believe both Cygwin and DJGPP provide independant libraries.


    I don't know about Cygwin, but DJGPP isn't _quite_ gcc, either. It's
    probably as close as it can get on MS-DOS, but I've seen people do
    things with gcc which I couldn't repeat with DJGPP.
    And DJGPP does come with its own, same-supplier libraries.

    Richard
    Richard Bos, Oct 9, 2003
    #12
  13. Ryan Lee

    Tim Prince Guest

    Richard Bos wrote:

    > CBFalconer <> wrote:
    >
    >> Richard Bos wrote:
    >> > Yes, that's the Gnu party line, but I've never seen GCC
    >> > without GLib.

    >>
    >> I believe both Cygwin and DJGPP provide independant libraries.

    >
    > I don't know about Cygwin, but DJGPP isn't _quite_ gcc, either. It's
    > probably as close as it can get on MS-DOS, but I've seen people do
    > things with gcc which I couldn't repeat with DJGPP.
    > And DJGPP does come with its own, same-supplier libraries.
    >
    > Richard

    cygwin includes the newlib library, which has no support for long double.
    <float.h> is written on the assumption that the CPU will be set to 53-bit
    precision mode, but there is no built-in support for setting that mode. I
    believe a number of embedded implementations of gcc use newlib.
    --
    Tim Prince
    Tim Prince, Oct 9, 2003
    #13
  14. Ryan Lee

    Dan Pop Guest

    In <F0chb.8992$> Tim Prince <> writes:

    >Richard Bos wrote:
    >
    >> CBFalconer <> wrote:
    >>
    >>> Richard Bos wrote:
    >>> > Yes, that's the Gnu party line, but I've never seen GCC
    >>> > without GLib.
    >>>
    >>> I believe both Cygwin and DJGPP provide independant libraries.

    >>
    >> I don't know about Cygwin, but DJGPP isn't _quite_ gcc, either. It's
    >> probably as close as it can get on MS-DOS, but I've seen people do
    >> things with gcc which I couldn't repeat with DJGPP.
    >> And DJGPP does come with its own, same-supplier libraries.
    >>
    >> Richard

    >cygwin includes the newlib library, which has no support for long double.
    ><float.h> is written on the assumption that the CPU will be set to 53-bit
    >precision mode, but there is no built-in support for setting that mode. I
    >believe a number of embedded implementations of gcc use newlib.


    And *all* Unix ports of gcc use whatever library comes with the system,
    which, except for Hurd and Linux, is NOT glibc. Bos is simply talking
    about something he has no clue about.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Oct 9, 2003
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ferran
    Replies:
    9
    Views:
    3,027
    Kevin Goodsell
    Apr 12, 2004
  2. JKop
    Replies:
    4
    Views:
    16,513
  3. Sydex
    Replies:
    12
    Views:
    6,483
    Victor Bazarov
    Feb 17, 2005
  4. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,185
    Peter Shaggy Haywood
    Sep 20, 2005
  5. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    796
    Peter Nilsson
    Jan 15, 2008
Loading...

Share This Page