Solution to the gcc error: undefined reference to `ilogb’ (C/C++)

The ilogb( ) functions return the exponent of their floating-point argument as a signed integer. If the argument is not normalized, ilogb( ) returns the exponent of its normalized value.

Here’s simple program that uses ilogb()


Now, if You use this function and get the following gcc linker error:

undefined reference to `ilogb’

That probably means that You did not tell gcc to link proper library (which contains ilogb function).

You can do this by using -lm switches. The -l means link a library. The m means the math library. You need to link the math library. This is the standard library that has common math functions like sqrt, sin, cos, log, etc. Linking makes these functions available to the main program.

Now You should be able to properly and successfully compile and link Your program.

$ gcc ilogb.c -lm

Leave a Reply

Your email address will not be published. Required fields are marked *