在gcc下用到数学函数,如sqrt。在gcc时要加上 -lm 参数,这样告诉编译器我要用到数学函数了 。

如:
gcc a.c -o a -lm

当在用Eclipse编译使用数学函数的C语言程序时,如sqrt,pow,即使已经加入math.h,也会提示类似于undefined reference to `sqrt’这样的错误。搜索得知需要给gcc加上-lm参数.
添加参数方法:

右键点击当前 project 选中 properties菜单->C/C++ build -> Settings -> GCC C Linker ->Libraries ->新建参数m

linux下编译时,链接math库

 

相关文章:

  • 2022-12-23
  • 2021-04-20
  • 2021-06-28
  • 2021-12-31
  • 2021-11-21
  • 2021-11-07
  • 2021-10-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-01-23
  • 2021-09-09
  • 2021-07-11
  • 2021-12-01
相关资源
相似解决方案