【问题标题】:I got a error message "undefined reference to `WinMain'"我收到一条错误消息“未定义对‘WinMain’的引用”
【发布时间】:2021-05-13 04:58:19
【问题描述】:

这是我的优先队列练习代码。

#include <stdio.h>
#include <stdlib.h>
#define MAX_ELEMENT 200

typedef struct{
    int key;
}element;


typedef struct{
    element heap[MAX_ELEMENT];
    int heap_size;
}HeapType;

// create function
HeapType* create()
{
    return (HeapType*)malloc(sizeof(HeapType)); 
}

// initialization function
void init(HeapType*h)
{
    h->heap_size = 0;   
} 

编译这段代码时,我收到一条消息“未定义对 `WinMain' 的引用”
程序通知我这一行有问题 > 'return (HeapType*)malloc(sizeof(HeapType)); '

我可以为这个问题做些什么?

【问题讨论】:

标签: c priority-queue


【解决方案1】:

要拥有一个完整的工作程序,您必须拥有一个 main() 函数。比如这个:

void main(void)
{
    HeapType *Heap;

    Heap = create();
    init(Heap);
}

很明显,你的代码基本上是不完整的......

【讨论】:

    【解决方案2】:

    没有main 代码,您的程序是不完整的,它会给您带来问题。 尝试在您的程序中包含void main(void){},然后查看是否存在问题。

    【讨论】:

      【解决方案3】:

      这是因为你没有main 函数。 main是所有应用程序的入口点(Windows中的GUI应用程序除外,入口点是WinMain)。如果您的程序没有入口点,它应该如何启动?它无法启动,因此出现错误。

      添加main 函数。

      int main() {
          /* Do all the stuff here,
          it seems you want to do things with your structs,
          do it here */
      }
      

      如果您的问题仍然存在,请确保您的应用程序未标记为 GUI,并确保不存在诸如 -mwindows-Wl,-subsystem,windows 之类的 gcc 标志。

      【讨论】:

        猜你喜欢
        • 2020-07-30
        • 2022-11-19
        • 2020-07-18
        • 2020-01-17
        • 2019-03-29
        • 1970-01-01
        • 2018-12-13
        • 2018-05-23
        • 1970-01-01
        相关资源
        最近更新 更多