c - C 中的 math.sqrt 问题

标签 c

为什么以下代码向我抛出错误 undefined reference to sqrt

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

int main(void)
{
    double i = 25;
    printf("\nSquare root of %d = %d",i,sqrt(i));
    return 0;
}

我已经包含了 ma​​th.h 并且我正在使用 Debian。谁能告诉我哪里出了问题。我需要重新安装我的库还是什么?

最佳答案

在命令行上使用 -lm 标志编译它以链接到数学库。

关于c - C 中的 math.sqrt 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5711902/

相关文章:

c - 基准测试-CPU时间大于墙时间?

c - 如何在Linux内核中使用vfs_readdir?

c - Balde - 设置问题

c - 读取文件并在每行的开头添加 10 个数组元素读取到数组我正在存储文件的行

二维数组中 8 位二进制的组合

c - 解释器在 C 中输入

c - C 中的数组及其指针

c - 使用 ncurses 在 C 中显示 "int **array"

c - 数组 C 中的最大值

c - 找出多组数字之间的最大差异