解决undefined reference to `pow’问题
问题现象
使用math库,
#include <math.h>
提示:
undefined reference to `pow’
解决方法
搜索
gcc -o test test.c -lm
或者
gcc test.c -lm -o test
或者
gcc test.c -o test -lm
man pow
SYNOPSIS
#include <math.h>
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);
Link with -lm.
Link with -lm.
.c
文件后使用-lm
生效
gcc 命令的常用选项
选项 | 解释 |
---|---|
-lLIBRARY | 连接时搜索指定的函数库LIBRARY。 |
其他
On 64-bits, pow() may be more than 10,000 times slower for some (rare) inputs than for other nearby inputs.
This affects only pow(), and not powf() nor powl().