C中变量的对数 [英] logarithm of a variable in C
本文介绍了C中变量的对数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我的代码有问题:
#include< stdio.h>
#include< math .h>
int main(){
int x;
x = 10;
printf("%。2f \ n",log(x));
}
当我尝试在GCC中编译它时会显示一条错误消息:
函数`main'':
logarithm.c :( .text + 0x19):未定义引用`log''
如何修复它?
Thans James
Hey, I have a problem with following code:
#include <stdio.h>
#include <math.h>
int main() {
int x;
x = 10;
printf("%.2f\n", log(x));
}
when I try to compile it in GCC it shows an error message:
In function `main'':
logarithm.c:(.text+0x19): undefined reference to `log''
how can I fix it?
Thans James
推荐答案
它为我编译(使用MinGW),这表明编译器命令行或缺少标准库或库错误的路径存在问题。
It compiles for me (using MinGW) which suggests a problem either with your compiler command line or with missing standard libraries or with the path to the libraries being wrong.
您使用的是C还是C ++?
更改 x 的定义,使其为双倍。
C ++支持三个名为 log 的不同函数。它使用magic来根据参数的类型确定三个中的哪一个使用。如果您正在使用C ++,那么可能通过 int 参数欺骗了魔法,寻找不存在的第四版 log 。
Are you using C or C++?
Change the definition of x so that it is a double.
C++ supports three different functions all named log. It uses magic to determine which of the three to use based on the type of the argument. If you''re using C++ then perhaps passing an int argument fooled the magic into looking for a nonexistent fourth version of log.
C ++会自动将int转换为浮点数,因此我怀疑Banfa是正确的,并且库已被排除在构建之外。
C++ would automatically convert the int to a float so I suspect Banfa is correct and a library has been left out of the build.
这篇关于C中变量的对数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文