GCC 中 undefined reference to ‘ceil’ collect2:ld returned 1 exit status 错误
来源:互联网 发布:网络语柚子是什么意思 编辑:程序博客网 时间:2024/06/01 10:35
当我们用gcc编译一个c文件时,如果用到了math.h中的一些数学函数,例如:ceil(),floor()等,可能会出现如下错误:
undefined reference to ‘ceil’
collect2:ld returned 1 exit status
主要是因为使用math.h中声明的库函数时,gcc命令行必须加-lm选项,如果没有加就会出现上面的错误,原因在于数学函数位于libm.so库文件中,-lm选项告诉编译器,我们程序中用到的数学函数要到这个库文件里找。我们平时用到的大部分函数(例如printf)位于libc.so库文件中,使用libc.so中的库函数在编译时不需要加-lc选项,是因为这个选项是gcc默认的选项。所以在使用gcc命令去执行c文件时,如果使用了math.h中的库函数的时候,一定要加-lm选项。《摘自linux c编程一站式学习》
例如:
gcc main.c -lm -o main
0 0
- GCC 中 undefined reference to ‘ceil’ collect2:ld returned 1 exit status 错误
- GCC 中 undefined reference to ‘ceil’ collect2:ld returned 1 exit status 错误
- undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
- undefined reference to `libiconv_open' collect2: ld returned 1 exit status
- undefined reference to `pthread_create' collect2: ld returned 1 exit status
- Linux gcc编译提示:undefined reference to `sqrtf' collect2: error: ld returned 1 exit status
- 【错误笔记】undefined reference to `sqrt' collect2: ld returned 1 exit status
- 编译器错误:/tmp/ccyOgqYQ.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
- pthread线程创建出现undefined reference to `pthread_create' collect2: error: ld returned 1 exit status
- undefined reference to `typeinfo for IA' collect2: ld returned 1 exit status
- undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit stat
- collect2: ld returned 1 exit status错误.
- collect2: ld returned 1 exit status错误.
- cocos2dx向android平台移植出现问题undefined reference to 'sqlite3_close' collect2: ld returned 1 exit status
- Linux gcc编译error:"collect2: ld returned 1 exit status"
- QT编译错误:collect2: ld returned 1 exit status
- Android 编译错误:collect2: ld returned 1 exit status
- QT中的error: collect2: ld returned 1 exit status错误
- 如何配note,打补丁
- 关于固定资产的分录
- 命令行标准
- HDOJ 2199 Can you solve this equation?
- 文件夹的拷贝
- GCC 中 undefined reference to ‘ceil’ collect2:ld returned 1 exit status 错误
- Opencv 例程讲解 6 ---- 图片融合 addWeighted到底有多快?
- 电源管理之android内核suspend to disk的实现(一)
- Hibernate Annotation @mappedBy含义
- 【LeetCode】48 Rotate Image && 【九度】题目1164:旋转矩阵
- WebClient与WebRequest差异
- linux常用命令
- 关于openGL的一些链接,主要是GLSL(不断更新)
- mysql中int、bigint、smallint 和 tinyint的区别与长度的含义