簡體   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