在自己编写的函数中调用数学函数时,如下例子:

#include<stdio.h>
#include<math.h>
void p(void)
{
    printf("%g\n", pow(2, 3));
}
        
int main()
{
    p();
    return 0;
}

出现编译问题:

undefined reference to `pow'

解决方法:

gcc pow.c -lm

问题:

为什么在函数中调用math.h头文件需要加 -lm参数,而在main中调用却不需要? 

相关文章:

  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2021-04-20
猜你喜欢
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案