Thread: undefined symbols

  1. #1
    Registered User cDev's Avatar
    Join Date
    Jun 2006
    Posts
    26

    undefined symbols

    Working on a mac and getting an 'undefined symbols' error when I try to compile this push pop program. I don't see a problem in my code; I'm wondering if it could be a problem with the gcc version I have? If anyone can help it would be most appreciated

    Here's my code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>		/* for atof() */
    
    #define MAXOP	100		/* max size of operand or operator */
    #define NUMBER	'0'		/* signal that a number was found */
    
    int getop (char []);
    void push (double);
    double pop (void);
    
    /* reverse Polish calculator */
    main()
    {
    	int type;
    	double op2;
    	char s[MAXOP];
    	
    	while ((type = getop(s)) != EOF)
    	{
    		switch (type)
    		{
    		case NUMBER:
    			push (atof(s));
    			break;
    		case '+':
    			push(pop() + pop());
    			break;
    		case '*':
    			push(pop() * pop());
    			break;
    		case '-':
    			push(pop() - op2);
    			break;
    		case '/':
    			op2 = pop();
    			if (op2 != 0.0)
    				push(pop() / op2);
    			else
    				printf("error: zero divisor\n");
    			break;
    		case '\n':
    			printf("\t%.8g\n", pop());
    			break;
    		default:
    			printf("error: unknown command %s\n", s);
    			break;
    		}
    	}
    	return 0;
    }
    Here's my error:
    Code:
    /usr/bin/ld: Undefined symbols:
    _getop
    _pop
    _push
    collect2: ld returned 1 exit status

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > void push (double);
    This is a prototype, it only tells the compiler that the function exists somewhere.

    You need to actually implement it as well
    Code:
    void push (double) {
      // your code here
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User cDev's Avatar
    Join Date
    Jun 2006
    Posts
    26
    Thanks, I had a feeling that might have been the case...I added in the missing functions and it works now

  4. #4
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    There seems to be a flurry of these RPN calculators lately. The funny thing (for me) is I've just written one too, after a fashion - a very very poor Forth implementation that, at this very moment, is half crippled.

    Just an aside.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >a very very poor Forth implementation that, at this very moment, is half crippled.
    How does one write a "very poor" Forth implementation?
    My best code is written with the delete key.

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I think that's his attempt at being modest by doubting his own ability.

  7. #7
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    It hasn't got a dictionary. Actually I don't think it qualifies as a Forth. The most it can do is something like:

    Code:
    120 23 + .s drop
    It started life as one of my many fiddles with writing a tokeniser.
    EDIT:
    >> Actually I don't think it qualifies as a Forth

    By that I mean I don't think it complies with the standard. I'll go have a look-see now.
    Last edited by cboard_member; 09-24-2006 at 12:25 PM.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM