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

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

  1. Hello All
    Thanks for checking out my writing website . My name is Noah Wilkinson.
    I have worked since high school in this niche. My interest in writing started at a young age. I wrote poetry as a child and eventually went on to work with my school newspaper.
    This early tryst into journalism eventually led me to academic writing. There is plenty of work for qualified writers. I specialize in research papers , but have the skills to do all types of academic writing.
    Contact me for more information about rates and a price quote. I’m looking forward to helping you.

    Academic Writer – Noah – Funnyhomework Corps

Leave a Reply

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