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