小编use*_*106的帖子

gcc似乎找不到数学库

我正在尝试用C执行一个非常简单的代码:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#ifndef M_PI
 #define M_PI 3.14
#endif 

double cosrad (double n)
{
    double rad = n*(M_PI)/180.0;
    double res = cos(rad);
    return res;
}

int main (int argc, char** argv)
{
    printf ("cosrad 90 = %f\n", cosrad(90));
    printf ("cos pi/2 = %f\n", cos(M_PI/2.0));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但在使用此命令行(使用-lm)进行编译时,出现错误.似乎没有找到数学库.

$gcc -Wall -Werror -std=c99 -O0 -lm -g -o foo foo.c
.c:12: undefined reference to `cos'
collect2: ld a retourné 1 code d'état d'exécution
Run Code Online (Sandbox Code Playgroud)

这真是奇怪,因为代码:

 printf ("cos pi/2 = …
Run Code Online (Sandbox Code Playgroud)

c math gcc

1
推荐指数
1
解决办法
354
查看次数

将 DURATION HH:MM:SS 转换为 bash 中的秒数

我想找到一种方法可以轻松地将持续时间(而不是 1970 年等的时间等)转换为以秒为单位的持续时间,例如 05:42:32。请问有没有一种简单快捷的方法可以在 bash 中做到这一点?我尝试了“日期”和 %s 等,但它总是返回自 1970 年以来的时间,我只想要一个持续时间。

谢谢 !

bash time duration

1
推荐指数
1
解决办法
4869
查看次数

标签 统计

bash ×1

c ×1

duration ×1

gcc ×1

math ×1

time ×1