Thread: error: undefined reference to pointer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    20

    Question error: undefined reference to pointer

    Hi all,

    I'm developing a compiler and at this stage I'mhaving problems compiling one of the files ("tabela_simbolos.c"). Here's the .c and .h and the error messages:

    tabela_simbolos.c
    Code:
    #include "tabela_simbolos.h"
    
    #include <malloc.h>
    #include <string.h>
    #include <stdio.h>
    
    extern elemento_tabela* simbolo_tabela;
    
    //Insere um novo identificador na cauda de uma lista ligada de símbolos
    elemento_tabela *insere_elemento(char *str, tipo_basico t)
    {
    	elemento_tabela *novo_simbolo=(elemento_tabela*) malloc(sizeof(elemento_tabela));
    	elemento_tabela *aux;
    	elemento_tabela* anterior;
    
    	strcpy(novo_simbolo->nome, str);
    	novo_simbolo->tipo=t;
    	novo_simbolo->proximo=NULL;
    
    	if(simbolo_tabela)	//Se a tabela já tem elementos
    	{	//Procura cauda da lista e verifica se simbolo ja existe (NOTA: assume-se uma tabela de simbolos globais!)
    		for(aux=simbolo_tabela; aux; anterior=aux, aux=aux->proximo)
    			if(strcmp(aux->nome, str)==0)
    				return NULL;
    		
    		anterior->proximo=novo_simbolo;	//adiciona ao final da lista
    	}
    	else	//simbolo_tabela tem um elemento -> o novo símbolo
    		simbolo_tabela=novo_simbolo;
    
    	return novo_simbolo;
    }
    
    void mostra_tabela()
    {
    	elemento_tabela *aux;
    	printf("\n");
    
    	for(aux=simbolo_tabela; aux; aux=aux->proximo)
    		printf("símbolo %s, tipo %d\n", aux->nome, aux->tipo);
    }
    
    //Procura um identificador, devolve 0 caso não exista
    elemento_tabela *procura_elemento(char *str)
    {
    	elemento_tabela *aux;
    
    	for(aux=simbolo_tabela; aux; aux=aux->proximo)
    		if(strcmp(aux->nome, str)==0)
    			return aux;
    
    	return NULL;
    }
    tabela_simbolos.h
    Code:
    #ifndef TABELA_SIMBOLOS_H
    #define TABELA_SIMBOLOS_H
    
    typedef enum {INTEIRO, FLOAT, CARACTER} tipo_basico;
    
    typedef struct _t1
    {
    	char nome[32];
    	tipo_basico tipo;
    	struct _t1 *proximo;
    } elemento_tabela;
    
    elemento_tabela *insere_elemento(char *str, tipo_basico t);
    void mostra_tabela();
    elemento_tabela *procura_elemento(char *str);
    
    #endif
    /tmp/cc2MnpKE.o: In function `insere_elemento':
    tabela_simbolos.c.text+0x3b): undefined reference to `simbolo_tabela'
    tabela_simbolos.c.text+0x44): undefined reference to `simbolo_tabela'
    tabela_simbolos.c.text+0x90): undefined reference to `simbolo_tabela'
    /tmp/cc2MnpKE.o: In function `mostra_tabela':
    tabela_simbolos.c.text+0xb2): undefined reference to `simbolo_tabela'
    /tmp/cc2MnpKE.o: In function `procura_elemento':
    tabela_simbolos.c.text+0xf0): undefined reference to `simbolo_tabela'
    collect2: ld returned 1 exit status
    If anybody has an idea of the cause of the error, I'd appreciate to know your opinion :|

    Many thanks,
    João Fernandes
    Last edited by blacknail; 09-13-2008 at 03:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  3. Using Vectors. MinGW warning
    By Viewer in forum C++ Programming
    Replies: 9
    Last Post: 03-26-2009, 03:15 PM
  4. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  5. C++ pointer vs reference
    By C-Dumbie in forum C++ Programming
    Replies: 4
    Last Post: 11-04-2002, 04:08 AM

Tags for this Thread