开发者

floor of double(time_t)

I cannot understand why this throws undefined reference to `floor'":

dou开发者_如何转开发ble curr_time = (double)time(NULL);
return floor(curr_time);

Hasn't it been casted to double, which is what floor receives?


You possibly have run in to the infamous -lm problem: Compile as:

gcc yourfile.c -o out -lm 

This is C FAQ 14.3 item as well.


Maybe because you don't link with the math library? The error has nothing to do with casts and data types, btw.


You probably have to link explicitly to the library. On an UNIX-like system this would typically be "/usr/lib/libm.a". The C standard library should be linked by default, but the math library is, depending on your system, not linked and you may have to link explicitly. (e.g. on Mac OS X it is also linked by default on my ubuntu system it is not).

Note that this has nothing to do with your include path. If you are on something UNIX-like you will probably find the header with the prototype declaration under "/usr/include/math.h", where your compiler will always look for headers.

If you are using gcc, you can either link directly with:

gcc yourfile.c /usr/lib/libm.a -o out

or with "-lnameroflibrary" like this:

gcc yourfile.c -lm -o out

this will look for a library in the same directory as the C standard library with the name "libnameoflibrary.a"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜