简体   繁体   English

底数double(time_t)

[英]floor of double(time_t)

I cannot understand why this throws undefined reference to `floor' ": 我不明白为什么这会引发对“ floor”的未定义引用

double 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: 您可能遇到了臭名昭著的-lm问题:编译为:

gcc yourfile.c -o out -lm 

This is C FAQ 14.3 item as well. 这也是C FAQ 14.3项。

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". 在类似UNIX的系统上,它通常是“ /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. 默认情况下,应链接C标准库,但根据您的系统,数学库未链接,您可能必须显式链接。 (eg on Mac OS X it is also linked by default on my ubuntu system it is not). (例如,在Mac OS X上,在我的ubuntu系统上默认也未链接)。

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. 如果您使用的是类似UNIX的系统,则可能会在“ /usr/include/math.h”下找到带有原型声明的标头,在此您的编译器将始终在其中查找标头。

If you are using gcc, you can either link directly with: 如果您使用的是gcc,则可以直接链接:

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

or with "-l nameroflibrary " like this: 或像这样的“ -l nameroflibrary ”:

gcc yourfile.c -lm -o out

this will look for a library in the same directory as the C standard library with the name "lib nameoflibrary .a" 这将在与C标准库相同的目录中查找名称为“ lib nameoflibrary .a”的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM