Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"undefined reference to `ceilf'"

Tags:

c

eclipse

Simple question. I'm importing code previously written by someone else into eclipse. I am getting the error:

"undefined reference to `ceilf'"

when I use ceilf. It appears to me that ceilf is suppose to be contained in the math.h library which is included in my file. However, when I open up the /usr/include/math.h file I don't see a ceilf method defined. In fact as far as I can tell none of the math.h files on my redhat deployment have a ceilf method. Any idea where the wayward ceilf method is defined? Since this code works and even compiles elsewhere the issue has to be with my configuration rather then the code itself.

ps. I can use the regular ceil method. I've considered just switching to it, but it would be less efficent in a critical path of the program. Yes I know premature optimization is evil, but I'm asking as much out of curiousity as to why I would have the error anyways. I can't see why my math.h files wouldn't defile it.

EDIT:: thank you for explaining why I can't find the ceilf function, I understand that problem. However, I don't know how to appease eclipse. I've tried setting the compiler option to use std=c99 as suggested and it doesn't remove the error. In fact I thought eclipse was just using my Makefile to do the build, and the make file doesn't throw the exception. Is there something I can do to cause the editor to realize I have the file defined?

like image 558
dsollen Avatar asked Sep 03 '26 10:09

dsollen


2 Answers

ceilf is part of the math library, so you need to link with -lm to use it. Just #include <math.h> is not enough.

like image 162
Chris Dodd Avatar answered Sep 06 '26 02:09

Chris Dodd


According to the manual page:

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       ceilf(), ceill():
           _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 600 ||
           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L;
           or cc -std=c99

Try setting the standard to C99 in your compiler or enabling one of these feature-test macros.

Also make sure you're linking with -lm or the appropriate switch for your platform and compiler to link the math library.

like image 26
Chris Browne Avatar answered Sep 06 '26 02:09

Chris Browne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!