Thread: Do not understand this error

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    151

    Do not understand this error

    OK im getting one more error while compiling

    Undefined first referenced
    symbol in file
    main /usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/crt1.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status

    ...
    THere is no line number given.What does this mean?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    It means you're referencing an identifier that has no definition that it can see. Why don't you post your code?
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    151
    Its a huge code

    Code:
    #include<string.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "stack.h"
    
    /*
     * *********************************StackInit
     * A new stack variable is initialized.  The initialized
     * stack is made empty.
     * INPUT: stackP
     * OUTPUT:void
     */
    
    void StackInit(stackST *stackP)
    {
      stackElement *newContents;
    
      /* Allocate a new array to hold the contents. */
    
      newContents = (stackElement *)malloc(sizeof(stackElement) * 10);
    
      stackP->contents = newContents;
      stackP->lineST = 0;
      stackP->top = -1;  /* I.e., empty */
    }
    
    
    /*
     * ******************************StackPush
     * Add an element to the top of the stack
     * INPUT: stackP. element and the line number where the tag was found
     * OUTPUT:void
     *
     */
    
    void Push(stackST *stackP, stackElement element, int line)
    {
    
      /* Put information in array; update top. */
    
      stackP->contents[++stackP->top] = element;
      stackP->lineST=line;
    }
    
    
    /*
     * ******************************StackPop
     * Remove an element from the top of the stack.It first checks if the previous opening tag is closed,
     * else it displays an error and recursively checks if the next opened tag has been closed.
     * INPUT: stackP. element and the line number where the tag was found
     * OUTPUT:void
     *
     */
    
    stackElement Pop(stackST *stackP, char *checkelement, int line)
    {
    
      	if	(strcmp(checkelement,stackP->contents)==0)
        return stackP->contents[stackP->top--];
        else
        {
           printf("\n Error: unmatched tag </%s>in line %d corresponding to line %d",checkelement,line,stackP->lineST);
           stackP->top--;
           return Pop(stackP,checkelement,line);
        }
    
    }

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Do you have a main function somewhere?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    That's not your whole code. I don't see anything wrong with that file itself (that would cause a linker to throw errors: there are a few code issues (don't cast malloc()).

    Suggestions:
    1) You can attach code rather than pasting if you feel it is too big for a post.
    2) You do have a main(), don't you?
    3) Try a clean compile. (Perhaps with -Wall too)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    151
    This is my main method

    Code:
    #include <stdio.h>
    #include <string.h>
    #include "stack.h"
    #include <stdlib.h>
    
    
    int main(void)
    {
    	stackST s1;
    	int line = 0;
    	char c;
    	char element[10];    /* Tag that is captured.*/
    	char newelement[10]; /* New element to be pushed.*/
    	char check[10];   /* Check tag that is sent to the pop function*/
    	int i=0;/*counters*/
    	int j,k=0;/**/
    	int *temp;/* temporary pointer to copy only the words in the tag leaving out unnecessary input like <>*/
    	char code[500];/* each line that is parsed from the input file*/
    
        /*Initializes the stack*/
    	stackInit(&s1);
    
    	while (scanf("%s",code)!=EOF)
    	{
    
    		++line;
    		while (i<strlen(code))
    		{
    			c=code[i];
    			if (c == '<')
    			{
    
    	            j=0;
    	            do
    	            {
    					c=code[i];
    					element[j++]=c;
    					code[i++];
    				}while(c!='>');
    
    
    				if (element[1] == '/') /* if close tag*/
    				{
    					*temp=element[2];
    					k=0;
    					while(k<=strlen(element)-3)
    					check[k++]=putchar(*temp++);
    					Pop(&s1, check,line);
    					printf("%s",element);
    
    				}
    				else if(element[1] == '!')/* if comments, that should be delted from the output*/
    				{}
    				else        /* If opening tag*/
    				{
    					*temp=element[1];
    					k=0;
    					while(k<=strlen(element)-2)
    					newelement[k++]=putchar(*temp++);
    
    					Push(&s1,newelement,line);
    					printf("%s",element);
    
    				}
    
    			}
    			else
    			printf("%c",c);/* print everything that is not a tag*/
    
    		}
    	}
    	printf("\n \n \n File was successfully verified");
    	putchar('\n');
    	return 0;
    }

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    151
    stack.h

    Code:
    #include <stdlib.h>
    
    typedef char stackElement; /* the type of the objects entered in the stack.*/
    
    
    /* Stack structure*/
    typedef struct {
    	stackElement *contents;
    	int top;
    	int lineST;
    }stackST;
    
    void StackInit (stackST *stackP);
    
    void Push(stackST *stackP, stackElement element, int line);
    
    stackElement Pop(stackST *stackP, char *checkelement, int line);

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    151

    Arrow

    Why do you say not to use the malloc function?

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    He didn't say don't use malloc, he said don't cast malloc.
    Sent from my iPadŽ

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    I'd say crank up the warnings level on your compiler and try to fix the compiler issues first (like what do you want this to do?).
    Code:
    	            do
    	            {
    					c=code[i];
    					element[j++]=c;
    					code[i++];
    				}while(c!='>');
    The changes mentioned in your other thread cascade through the code, so there are a number of places to fix.
    Code:
    void Push(stackST *stackP, stackElement element, int line)
    {
    
      /* Put information in array; update top. */
    
      stackP->contents[++stackP->top] = element;
      stackP->lineST=line;
    }
    element needs to be a pointer, and that changes things as well.
    Code:
       int *temp;/* temporary pointer to copy only the words in the tag leaving out unnecessary input like <>*/
    Don't let this pointer dangle.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  11. #11
    Registered User
    Join Date
    May 2006
    Posts
    151
    I didnt understand what you meant bout thelast 2 changes. Please explain.
    Thanks.

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    151
    I mean I didnt understand the last error about the pointer dangling.

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The pointer is not initialized. It points to nothing and something. It points to something that is nothing, yet does not fit the definition of nothing. It it a very profound concept, understood by very few. Mastered by even fewer. Ponder this. Study its meaning, Grasshopper.


    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    That was beautiful, quzah.

  15. #15
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM