c - 未定义对 `Function' C 的引用

标签 c compiler-errors

<分区>

我已经研究了这个错误的解决方案,但我还是不明白。

#include <stdio.h>

float calcF(float a, float b, float c); 

int main(void) 
{
float mag_flux_den, cur, len; 
float result;

printf("What is the magnetic flux density in tesla? : ");
scanf("%f", &mag_flux_den);
printf("What is the current in the conductor in Amperes? : ");
scanf("%f", &cur);
printf("What is the length of the conductor in the magnetic field in metres? : ");
scanf("%f", &len);

result = calcF(mag_flux_den, cur, len);

printf("Force on the current carrying conductor: %f", result);
return 0;
}

float calcf(float a, float b, float c) //calculates force on the current carrying conductor{
      float F;
F = a * b * c;
return F;   
}

我正在使用 ideone.com,但仍然收到相同的错误消息(undefined reference to 'calcF')。任何帮助将不胜感激。

最佳答案

您将函数声明为带有大写字母“F”的“calcF”,但您的定义是带有小写字母“f”的“calcf”。确保它们相同。

此外,代码块底部的函数定义在注释末尾有一个左括号。

把它移到评论后面。

关于c - 未定义对 `Function' C 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35661715/

相关文章:

sass - 添加图标字体Ionic 3时出错

arrays - char 之前的预期表达式

c++ - 代码编译错误

c - 来自 Linux 内核模块的暂停指令不起作用

c - 将数字数据存储在二进制文件和数据结构中

c++ - 混合使用 C 和 C++ 代码会在 GCC 中产生意外行为

c - ((size_t *)(vec))[-1] 是否违反严格别名?

c++ - 使用 C++ 和 bcrypt header 时出现编译错误

python - 我想从 log.txt 文件中获取这个字符串怎么办

ios - 在 Xcode 10 上出现错误 : "Swift does not support the SDK ' iPhoneSimulator11. 2.sdk'"