stack make file problem

This is a discussion on stack make file problem within the C Programming forums, part of the General Programming Boards category; I am trying to compile a makefile program with a stack. Here's all the code makefile # makefile for stack_prog ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    stack make file problem

    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.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    previous stack problem

    I misstated the error message:

    admiral% make
    gcc -c stack_main.c
    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'

    Thanks,

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    stack makefile problem

    Found my problem, sorry for the bother here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21