gpt4 book ai didi

C 轮函数抛出错误 : "undefined reference to ` round'. ..”

转载 作者:行者123 更新时间:2023-11-30 15:05:57 27 4
gpt4 key购买 nike

我希望有人能帮助我。我正在研究 CS50x 并正在研究 Pset1 - 贪婪。每当我编译代码时,都会收到以下错误:

/tmp/greedy-46be96.o: In function `main':
greedy.c:(.text+0x95): undefined reference to `round'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

任何帮助将不胜感激。如果问题含糊不清,我深表歉意,我已尽力深入探讨。我在终端中使用了man round,并到处搜索,尝试了不同的解决方案,但没有任何效果。

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

int main(void)
{
float owed;
float change;
float quarter = 0.25;
float dime = 0.10;
float nickel = 0.05;
float penny = 0.01;

do {
printf("How much change is owed?: ");
owed = GetFloat();

} while(owed <= 0);

change = round(owed * 100);
}

我正在使用此命令来编译我的代码:

clang -o greedy greedy.c -lcs50

最佳答案

编译时,以下内容应该起作用:

clang -o greedy greedy.c -lcs50 -lm

这链接了编译器的数学库。

关于C 轮函数抛出错误 : "undefined reference to ` round'. ..”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39472662/

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