gpt4 book ai didi

c - 尽管包含 math.h,但在 C 中未定义对 pow( ) 的引用

转载 作者:太空狗 更新时间:2023-10-29 16:16:15 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Problem using pow() in C
what is 'undefined reference to `pow''

我对一个简单的 uni 类(class)作业有一点疑问,这让我很困惑。

基本上,我必须编写一个程序,除其他外,计算给定半径的球体的体积。我想我会使用 pow() 函数而不是简单地使用 r*r*r 来获得额外的 Brownie 点数,但是编译器一直给我以下错误:

undefined reference to 'pow' collect2: error: ld returned 1 exit status

我的代码如下所示:

#include <math.h>

#define PI 3.14159265 //defines the value of PI

/* Declare the functions */
double volumeFromRadius(double radius);

/* Calculate the volume of a sphere from a given radius */
double volumeFromRadius(double radius) {
return (4.0/3.0) * PI * pow(radius,3.0f);
}

我正在使用命令 gcc -o sphere sphere.c

进行编译

这在 uni 的 Windows 机器上的 code::blocks 中编译和运行良好,但在我家里的 Fedora 17 上,命令行编译器拒绝运行。任何想法将不胜感激!

祝福,伊恩

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com