Reputation: 93
The code i want to run has the makefile and it shows the error:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [Nfa] Error 1
The file with the main function is terp.c.
The part of the code with main() is:
#ifdef MAIN
#define ALLOCATE
#include "global.h" /*externs for Verbose*/
#define SIZE 256
PRIVATE char BUf[BSIZE] //input buffer
PRIVATE char *Pbuf=BUf; //current position in input buffer
PRIVATE char *Expr; //regular expression from command Line
...
Skipping some code here until main...
void main (int argc,char *argv[])
{
int sstate; //Starting NFA state
SET *start_dfastate;//Set of starting DFA states
SET *current; //current DFA state
SET *next;
int accept; //current Dfa state is an accept
int c; //current input character
int anchor;
if (argc==2)
fprintf(stderr,"Expression is %s\n",argv[1]);
else
{
fprintf(stderr,"Usage:terp pattern < input\n");
exit(1);
}
//Compile the NFA create the initial state,and initialize the current state to the start state
Expr=argv[1];
sstate=nfa(getline);
next=newset();
ADD(next,sstate);
if (!(start_dfastate=e_closure(next,&accept,&anchor)))
{
fprintf(stderr,"Internal error:State machine is empty\n");
exit(1);
}
current=newset();
assign(current,start_dfastate);
while (c=nextchar())
{
if (next=e_closure(move(current,c),&accept,&anchor))
{
if (accept)
printbuf();
else
{
delset(current);
current=next;
continue;
}
}
delset(next);
assign(current,start_dfastate);
}
}
#endif
The makefile i am using:
FILES.o=set.o hash.o printnfa.o input.o nfa.o terp.o assort.o prnt.o printv.o bintoasc.o ferr.o onferr.o fputstr.o pchar.o driver.o searchenv.o hashadd.o esc.o
PROGRAM= Nfa
INC := -I./debug.h -I./global.h
all: ${PROGRAM}
${PROGRAM}: ${FILES.o}
${CC} -o $@ ${CFLAGS} $(INC) $^ ${LDFLAGS} ${LDLIBS}
Upvotes: 0
Views: 160
Reputation: 8614
Since your first line is:
#ifdef MAIN
I would say you need to define that when compiling.
Use -DMAIN
as a preprocessor option for gcc
in the makefile
(you can put this line below the INC
line):
CFLAGS=-DMAIN
This way, it will be included when the compiler is actually called:
${CC} -o $@ ${CFLAGS} $(INC) $^ ${LDFLAGS} ${LDLIBS}
▲
║
╚═══ This will include the `MAIN` definition for compiling
The other option is to remove the #ifdef MAIN
alltogether. Don't forget the remove the corresponding #endif
from the end of the file.
Upvotes: 3