I am trying to compile a makefile program with a stack.
Here's all the code
makefile
# makefile for stack_prog
stack_prog: stack_main.o stack.o
gcc stack_main.o stack.o -o stack_prog
stack_main.o: stack_main.c stack.h
gcc -c stack_main.c
stack.o: stack.c stack.h
gcc -c stack.c
stack_main
/* stack_main.c */
/* A program to implement a stack ADT */
/* using an array of integers */
#include <stdio.h>
#include "stack.h"
#define STACKSIZE 5
main()
{
int mystack[STACKSIZE] = {0}; /* stack declared here */
initialize();
printf("empty: %d\n",empty());
printf("full: %d\n",full());
push(mystack,2);
printf("empty: %d\n",empty());
printf("full: %d\n",full());
printf("pop: %d\n",pop(mystack));
push(mystack,2);
push(mystack,4);
push(mystack,6);
push(mystack,8);
push(mystack,10);
printf("empty: %d\n",empty());
printf("full: %d\n",full());
return 0;
}
stack.c
#include <stdio.h>
#include "stack.h"
#define STACKSIZE 5
int count;
void make_empty(void)
/* This function sets value of count to 0. */
/* Note that the items of the stack are NOT */
/* set to any particular values */
{
count = 0;
return;
}
int is_empty(void)
/* This function will determine if the stack is empty */
/* by testing the value of the stack counter: if it is 0, */
/* function prints "stack empty" and returns a value of 1; */
/* otherwise, function returns a value of 0. */
{
if (!count)
printf("\nstack empty!\n");
return !count;
}
int is_full(void)
/* this function will determine if the stack is full */
/* by testing the value of the stack counter: if it is */
/* equal to STACKSIZE, function prints "stack full" */
/* and returns 1; otherwise, returns a value of 0. */
{
if (count>=STACKSIZE)
{ printf("\nstack FULL!\n");
return 1;
}
else
return 0;
}
int pop(int stack[])
/* First, this function will decrement the stack counter */
/* Then, an array element with current subscript (which */
/* is the value of a stack counter) will be returned. */
{
if (!empty())
return stack[--count];
return 0;
}
void push(int stack[],int item)
/* Parameters of this function are: an array 'stack' and an */
/* integer 'item'. The integer is pushed onto the stack and */
/* the the stack counter is incremented. The function does NOT */
/* have any return value, but an array has changed, because it */
/* was passed by address (or, by reference). */
{
stack[count++] = item;
return;
}
Heres the error message from my gcc compiler:
admiral% make
gcc -c stack.c
gcc stack_main.o stack.o -o stack_prog
Undefined first referenced
symbol in file
full stack_main.o
initialize stack_main.o
empty stack_main.o
ld: fatal: Symbol referencing errors. No output written to stack_prog
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `stack_prog'
If anyone can see my error I will be very grateful.