0

I'm trying to implement stack in C and it got the weird error in my MinGw compiler

 gcc -Wall -o stack stack.c 

Stack.c

#include "stack.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>


Stack *create(int size) {
    Stack *result;
    result = (Stack *) malloc(  sizeof(Stack) * size );
    assert(result != NULL);

    result -> file = result;
    result -> maxAllocate = size;
    result -> top = -1;
    return result;
}

stack.h

#define MAX_SIZE 1024

typedef struct {
    void **file;    
    int top;     
    int maxAllocate; // current size of array allocated for stack
} Stack;

Stack *create(int size);        
int   push(Stack *s, void *x);  
void  *pop(Stack *s);           
int   isEmpty(Stack *s);        

error

C:\test>gcc -Wall -o stack stack.c
stack.c: In function 'create':
stack.c:26:17: warning: assignment from incompatible pointer type [enabled by de
fault]
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function
 `main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMai
n@16'
collect2: ld returned 1 exit status
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
despacito2012
  • 73
  • 1
  • 11

2 Answers2

3

With gcc -Wall -o stack stack.c you compile only stack.c (which has o main function in it) but for a functioning application you will also need a main function, as the main entry point: http://en.wikipedia.org/wiki/Entry_point

Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
2

using gcc with -o option means you want to compile, link and run your program (this command won't run it, but usually that's the reason with such usage). You cannot run a program without an entry point (in this case it's main function).

If you only want to check if your stack.c compiles use gcc -Wall -c stack.c.

zoska
  • 1,684
  • 11
  • 23