use of long double

R

Ryan Lee

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
 
T

Tim Prince

Ryan said:
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.
 
R

Richard Bos

Tim Prince said:
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
 
E

Erik Trulsson

Richard Bos said:
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.)
 
R

Richard Bos

Erik Trulsson said:
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
 
D

Dan Pop

In said:
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!
It is never wise to muck about with the system header files. Write your
own additional header.


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
 
D

Dan Pop

In said:
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
 
T

Tim Prince

Richard said:
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.
 
D

Dan Pop

In said:
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
 
D

Dan Pop

In said:
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
 
R

Richard Bos

CBFalconer said:
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
 
T

Tim Prince

Richard said:
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.
 
D

Dan Pop

In said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top