编译器错误: undefined reference to `print'

标签 c compiler-errors

在我的代码中,尝试编译时我不断收到这些错误

/tmp/ccshIakV.o: In function `main':

project2.c:(.text+0x370): undefined reference to `print'

collect2: error: ld returned 1 exit status

这是我的代码

int main(void)
{
double a = 0;
double b = 0;
double c = 0;
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
double i = 0;

char command = '\0';

printf("\n      Welcome\n");
printf("     Aquapodz Stress Analysis Program\n");
printf("    ==================================\n");
while (command != 'x');
    {
printf("\n\n(a), (b), or (c), enter trial data for vendor.\n(f)ail-rate,     (m)ean stress, (s)ummary, e(x)it\n");
printf("Please enter a command");
scanf("%c", &command);

if (command == 'a')
{
printf("Please enter stress values (GPa) for this trial.");
scanf("%lf", &a);
scanf("%lf", &b);
scanf("%lf", &c);
}
else if (command == 'b')
{
printf("Please enter stress values (GPa) for this trial.");
scanf("%lf", &d);
scanf("%lf", &e);
scanf("%lf", &f);
}
else if (command == 'c')
{
printf("Please enter stress values (GPa) for this trial.");
scanf("%lf", &g);
scanf("%lf", &h);
scanf("%lf", &i);
}
else if (command == 'f')
{

printf("Average failure rate:\nAzuview:%f\nBublon:%f\nCryztal:%f\n",        a+b+c, d+e+f, g+h+i);
}
else if (command == 'm')
{
printf("Average mean stress:\nAzuview:%f\nBublon:%f\nCryztal:%f\n",     a+b+c/3, d+e+f/3, g+h+i/3);
}
else if (command == 's')
{
print("Total (pass / fail) so far:\nAzuview:%f(%f/0)\nBublon:%f(%f/0)    \nCryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);
}
else if (command == 'x')
{

}
else
{
printf("Invalid Command! Please Try Again :)");
}

}
printf("Goodbye, Please Come Again!");
  return 0;
}

我以前从未遇到过这些错误。

最佳答案

else if (command == 's')
{
    print("Total (pass / fail) so far:\nAzuview:%f(%f/0)\nBublon:%f(%f/0)    \nCryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);
}

仔细看看这部分。为了避免这种情况,请使用编译器警告(例如 gcc 的 -Wall -Wextra)——它们会在这种情况下警告隐式函数声明。

顺便说一句,关于许多其他行:如果没有要格式化的数据,则不需要 printf()。使用 puts() 代替(或者使用 fputs()stdout 如果不应该有换行符)。

关于编译器错误: undefined reference to `print' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31335048/

相关文章:

c - 如何在shell程序中实现&>和&>>?

c - 从客户端接受数据时出现段错误

表达式评估中的编译器差异

c - 有没有一种无需重新编码即可并行运行 C/C++ 程序的简单方法?

C:未定义的行为事实

c - 解释 C 宏

c++ - C 函数 'void msgBox(const char*, const char*)' 的声明与之前的声明冲突

java - 如何从命令行运行 Eclipse 编译的 Java 类?

python - 我的代码正在使用递归产生逻辑错误,但我不知道如何解决它

c++ - 我可以使用 CMake 编译我项目的不同警告级别的不同部分吗?