c - Undefined reference instead of makefile -
the code want run has makefile , shows error:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: in function `_start':(.text+0x20): undefined reference `main' collect2: error: ld returned 1 exit status make: *** [nfa] error 1
the file main function terp.c.
part of code main() is:
#ifdef main #define allocate #include "global.h" /*externs verbose*/ #define size 256 private char buf[bsize] //input buffer private char *pbuf=buf; //current position in input buffer private char *expr; //regular expression command line ...
skipping 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 accept int c; //current input character int anchor; if (argc==2) fprintf(stderr,"expression %s\n",argv[1]); else { fprintf(stderr,"usage:terp pattern < input\n"); exit(1); } //compile nfa create initial state,and initialize current state 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 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 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}
since first line is:
#ifdef main
i need define when compiling.
use -dmain
preprocessor option gcc
in makefile
(you can put line below inc
line):
cflags=-dmain
this way, included when compiler called:
${cc} -o $@ ${cflags} $(inc) $^ ${ldflags} ${ldlibs} ▲ ║ ╚═══ include `main` definition compiling
the other option remove #ifdef main
alltogether. don't forget remove corresponding #endif
end of file.
Comments
Post a Comment