C sinhl undefined reference when including math.h and linking libm

483 views Asked by At

Hoping someone has seen this before and can provide some insight.

I'm including math.h AND linking libm, using gcc 4.2.1 on FreeBSD 9.2 x86_64.

Functions like sinl, cosl, tanl work, but as soon as I call sinhl and the like I'm getting warnings about implicit declarations of built-in and errors for undefined references.

Relevant header section:

#include <math.h>
#include <stdlib.h>

// ....

long double function0(long double inValue)
{
    // Sine long double == sinl
    return sinl(inValue);
}

// ....

long double function3(long double inValue)
{
    // Hyperbolic Sine long double == sinhl
    return sinhl(inValue);
}

Makefile Stuff:

all:
        gcc -o test test.c -lm

Compile attempt results in:

function_references.h: In function 'function3':
function_references.h:39: warning: incompatible implicit declaration of built-in function 'sinhl'
/tmp//ccSpynxE.o: In function `function3':
test.c:(.text+0x98): undefined reference to `sinhl'

I checked math.h and both sinl and sinhl are listed the same way. Just for grins I tried linking against the 32-bit version of libm, which got me nowhere.

Interestingly enough, if I look at the symbols in /usr/include/libm.a, I see things for sinl but nothing for sinhl. Do I need to link other libraries to use the hyperbolic trig functions?

I've been poking at this on and off for the last 24-hours without seeing anything glaringly obvious. I experience the same problem for quite a few other functions as well: coshl,tanhl,logl,log2l,log10l,expl.

Any ideas from a fresh set of eyes?

Thank you in advance. -T

1

There are 1 answers

0
TCCSE On BEST ANSWER

@Giovanni Lombardo: thank you for getting me thinking down the track of the function missing entirely from the OS. Much appreciated.

The solution was to install "libmissing" for missing math functions.

For anyone else that runs into it:

  • Install /usr/ports/math/libmissing

  • Add the #include for missing_math.h to your code.

  • Update Makefile to include the path and linking for libmissing:
    gcc -I/usr/local/include -L/usr/local/lib -o test test.c -lm -lmissing