问题描述
在code我想运行具有生成文件,它显示了错误:
/usr/lib/gcc/x86_64-linux-gnu/4.7 /../../../的x86_64-Linux的GNU / crt1.o:在功能`_start ':(文字+ 0x20的):未定义引用'主'
collect2:错误:LD返回1退出状态
使:*** [NFA]错误1
在主要功能的文件是terp.c.结果
在code。与main()中的部分是:
#IFDEF MAIN
#定义ALLOCATE
#包括global.h/ *为实习医生详细* /的#define SIZE 256私人CHAR BUF [BSIZE] //输入缓冲区
私人的char * PBUF = BUF; //输入缓冲区的当前位置
私人的char * Expr的; //命令行定期EX pression...
跳过一些code这里,直到主...
无效的主要(INT ARGC,CHAR *的argv [])
{
诠释sstate; //开始NFA状态
SET * start_dfastate; //设置开始DFA状态
SET *电流; // DFA当前状态
SET *下一;
INT接受; //当前DFA广告状态是接受
INT℃; //电流输入字符
INT锚; 如果(的argc == 2)
fprintf中(标准错误,前pression为%s \\ n,ARGV [1]);
其他
{
fprintf中(标准错误,用法:TERP模式<输入\\ n);
出口(1);
}
//编译NFA创建的初始状态,并初始化当前状态到启动状态
EXPR =的argv [1];
sstate = NFA(函数getline);
接下来= newset();
ADD(接下来,sstate);
如果((start_dfastate = e_closure(接下来,&安培;!接受,&安培;锚)))
{
fprintf中(标准错误,内部错误:状态机是空\\ n);
出口(1);
}
电流= newset();
分配(电流,start_dfastate); 而(C = nextchar())
{
如果(下一= e_closure(移动(电流,C),放大器;接受和放大器;锚))
{
如果(接受)
printbuf();
其他
{
delset(电流);
电流=下一个;
继续;
}
}
delset(下);
分配(电流,start_dfastate);
}
} #万一
我使用的生成文件:
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 程序= NFA
INC:= -I./debug.h -I./global.h 所有:$ {设定} $ {设定}:$ {} FILES.o
$ {} CC -o $ @ $ {CFLAGS} $(INC)$ ^ $ {LDFLAGS} $ {} LDLIBS
由于您的第一行是:
#IFDEF MAIN
我会说你需要定义编译时。结果
使用 -DMAIN
为preprocessor为 GCC
在生成文件选项
(你可以把 INC
行下面这条线):
CFLAGS = -DMAIN
这个方式,将包括当编译器实际上是所谓的:
$ {} CC -o $ @ $ {CFLAGS} $(INC)$ ^ $ {LDFLAGS} $ {} LDLIBS
▲
║
╚═══这将包括编译`MAIN`定义
另一种选择是,以删除 #IFDEF MAIN
产品总数。不要忘了删除相应的 #ENDIF
从文件的结尾。
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}
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.
这篇关于未定义的引用,而不是生成文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!