0

This is my priority queue practicing code.

#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;   
} 

When I compile this code, I got a message "undefined reference to `WinMain'"
The program informed me that there was a problem on this line > 'return (HeapType*)malloc(sizeof(HeapType)); '

What can I do for this problem?

박성은
  • 1
  • 1
  • 4
    You don't have a `main` function. Is that expected? – iBug May 13 '21 at 05:02
  • Does this answer your question? [undefined reference to \`WinMain@16'](https://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16) – Gerhardh May 13 '21 at 08:37

3 Answers3

2

To have a complete working program, you have to have a main() function. For example this one:

void main(void)
{
    HeapType *Heap;

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

Obviously, your code is largely incomplete...

fpiette
  • 11,983
  • 1
  • 24
  • 46
0

Without the main code your program is incomplete and it will give you problems. Try to include void main(void){} in your program and then see if the problem exist.

moto
  • 38
  • 4
0

It's because you don't have a main function. main is the entry point to all applications(except GUI applications in Windows, the entry point is WinMain). If your program had no entry point, how's it supposed to start?, it can't start, hence the error.

Add a main function.

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

If your problem persists, make sure your application isn't marked as GUI, make sure gcc flags like -mwindows or -Wl,-subsystem,windows are not present.

Shambhav
  • 813
  • 7
  • 20