加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

函数指针指向C中的内置函数

发布时间:2020-12-16 06:51:21 所属栏目:百科 来源:网络整理
导读:我正在尝试设置一个指向pow功能的函数指针. 这是我的代码: #include stdio.h#include stdlib.h#include math.hint main(void){ double (*func)(double,double) = pow; return 0;} 但该程序无法编译. 我收到此错误: $gcc test.c -o test/tmp/ccD6Pmmn.o: In
我正在尝试设置一个指向pow功能的函数指针.
这是我的代码:

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

int main(void){
    double (*func)(double,double) = pow;
  return 0;
}

但该程序无法编译.
我收到此错误:

$gcc test.c -o test

/tmp/ccD6Pmmn.o: In function `main':
test.c:(.text+0x8): undefined reference to `pow'
collect2: error: ld returned 1 exit status

我正在使用Ubuntu 15.10.

谁知道我的代码有什么问题?

谢谢

解决方法

您需要通过命令行使用-lm进行编译,或者配置IDE以将其添加到链接过程中.这是因为有些库非常大并且为了避免在程序和编译时占用空间,这是在C的开头设置的,当时计算机速度慢得多,并且需要更多的编译和空间问题是CRUCIAL.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读