【问题标题】:how to use clang compile c file with math.h? [duplicate]如何使用 clang 编译带有 math.h 的 c 文件? [复制]
【发布时间】:2013-04-28 12:47:03
【问题描述】:
#include <stdio.h>
#include <math.h>

int main()
{
    printf("%.81f\n", 1+2*sqrt(3)/(5-0.1));
    return 0;
}

输出: /tmp/a4-4oU730.o:在函数main': a4.c:(.text+0x4f): undefined reference tosqrt' clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

【问题讨论】:

  • 如果你用谷歌搜索错误信息,就会出现数千种解决方案。

标签: c ubuntu clang math.h


【解决方案1】:

尝试将 -lm for libm for math 添加到您的构建命令中。也就是说,您的代码在 Mac OS 上使用 clang 4.1 对我来说可以正常工作。

【讨论】:

    猜你喜欢
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2014-03-03
    • 1970-01-01
    • 2021-11-23
    相关资源
    最近更新 更多