繁体   English   中英

最小脚本 Dev-C++ 上的“未定义对‘WinMain’的引用”错误

[英]'Undefined reference to `WinMain' ' error on minimal script, Dev-C++

我是 C 和编程新手。 我在 Windows 10 上,我刚刚安装了 Dev-C++,我正在学习如何从其他文件中调用函数:我写了这个 function 来对两个数字求和,我从主脚本中调用它。

问题是,当我编译 func.c 文件时,我得到标题错误,所以如果我运行主文件,它无法识别“总和”function。 这是main.c文件:

#include <stdio.h>
#include "func.h" 
    main(){
      int x,y,s;
      scanf("%d %d",&x,&y);
      s = sum(x,y);
      printf("\n%d",s); 
      }

这是 header 文件:

#ifndef FUNC_H_INCLUDED
#define FUNC_H_INCLUDED

int func(int a, int b);

#endif // FUNC_H_INCLUDED

这是 func.c 文件中总和 function 的代码:

#include <stdio.h>
#include "func.h"
int func(int a, int b){
    return(a+b);
}

我确实阅读了很多其他问题,但它们对我的情况没有帮助,或者我没有得到棘手的答案。 谢谢你。

如果您使用的是 Embarcadero 的 Dev-C++。 我使用他们的免费编译器,因为它是“可移植的”。

func.c and func.h both contain a function called func while your main file has a function called sum , you must have a consistency in the names, you can do s=func(x,y) and that should work, but a好的做法是做相反的事情,并用sum替换其他文件中的func 而且你必须编译这3个文件,编译1或2是不够的。

要使用 Embarcadero 的免费编译器编译它们:

C:\path\to\compiler\bcc32x func.c func.h main.c

它将为您提供可以从命令提示符运行的main.exe

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM