用户工具

站点工具


01-基础学习:课程:编译原理:实验:tiny:gcc编译问题

gcc编译tiny源码

makefile:

makefile
CC=gcc
CCFLAGS=-Wall
tiny:main.o analyze.o cgen.o code.o parse.o scan.o symtab.o util.o
clean:
	rm -rf *.o

出现的问题:

$ make
gcc    -c -o cgen.o CGEN.C
CGEN.C: In function 'void genStmt(TreeNode*)':
CGEN.C:32:44: warning: deprecated conversion from string constant to 'char*'
CGEN.C:39:53: warning: deprecated conversion from string constant to 'char*'
CGEN.C:43:52: warning: deprecated conversion from string constant to 'char*'
CGEN.C:46:58: warning: deprecated conversion from string constant to 'char*'
CGEN.C:46:58: warning: deprecated conversion from string constant to 'char*'
CGEN.C:52:53: warning: deprecated conversion from string constant to 'char*'
CGEN.C:52:53: warning: deprecated conversion from string constant to 'char*'
CGEN.C:54:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:58:48: warning: deprecated conversion from string constant to 'char*'
CGEN.C:62:63: warning: deprecated conversion from string constant to 'char*'
CGEN.C:67:66: warning: deprecated conversion from string constant to 'char*'
CGEN.C:67:66: warning: deprecated conversion from string constant to 'char*'
CGEN.C:68:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:72:48: warning: deprecated conversion from string constant to 'char*'
CGEN.C:77:53: warning: deprecated conversion from string constant to 'char*'
CGEN.C:77:53: warning: deprecated conversion from string constant to 'char*'
CGEN.C:78:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:82:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:82:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:84:51: warning: deprecated conversion from string constant to 'char*'
CGEN.C:84:51: warning: deprecated conversion from string constant to 'char*'
CGEN.C:90:40: warning: deprecated conversion from string constant to 'char*'
CGEN.C:90:40: warning: deprecated conversion from string constant to 'char*'
CGEN.C: In function 'void genExp(TreeNode*)':
CGEN.C:104:44: warning: deprecated conversion from string constant to 'char*'
CGEN.C:106:52: warning: deprecated conversion from string constant to 'char*'
CGEN.C:106:52: warning: deprecated conversion from string constant to 'char*'
CGEN.C:107:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:111:41: warning: deprecated conversion from string constant to 'char*'
CGEN.C:113:44: warning: deprecated conversion from string constant to 'char*'
CGEN.C:113:44: warning: deprecated conversion from string constant to 'char*'
CGEN.C:114:42: warning: deprecated conversion from string constant to 'char*'
CGEN.C:118:44: warning: deprecated conversion from string constant to 'char*'
CGEN.C:124:55: warning: deprecated conversion from string constant to 'char*'
CGEN.C:124:55: warning: deprecated conversion from string constant to 'char*'
CGEN.C:128:56: warning: deprecated conversion from string constant to 'char*'
CGEN.C:128:56: warning: deprecated conversion from string constant to 'char*'
CGEN.C:131:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:131:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:134:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:134:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:137:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:137:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:140:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:140:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:143:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:143:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:144:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:144:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:145:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:145:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:146:56: warning: deprecated conversion from string constant to 'char*'
CGEN.C:146:56: warning: deprecated conversion from string constant to 'char*'
CGEN.C:147:48: warning: deprecated conversion from string constant to 'char*'
CGEN.C:147:48: warning: deprecated conversion from string constant to 'char*'
CGEN.C:150:46: warning: deprecated conversion from string constant to 'char*'
CGEN.C:150:46: warning: deprecated conversion from string constant to 'char*'
CGEN.C:151:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:151:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:152:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:152:49: warning: deprecated conversion from string constant to 'char*'
CGEN.C:153:56: warning: deprecated conversion from string constant to 'char*'
CGEN.C:153:56: warning: deprecated conversion from string constant to 'char*'
CGEN.C:154:48: warning: deprecated conversion from string constant to 'char*'
CGEN.C:154:48: warning: deprecated conversion from string constant to 'char*'
CGEN.C:157:51: warning: deprecated conversion from string constant to 'char*'
CGEN.C:160:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C: In function 'void codeGen(TreeNode*, char*)':
CGEN.C:197:40: error: invalid conversion from 'void*' to 'char*'
CGEN.C:200:45: warning: deprecated conversion from string constant to 'char*'
CGEN.C:203:35: warning: deprecated conversion from string constant to 'char*'
CGEN.C:204:57: warning: deprecated conversion from string constant to 'char*'
CGEN.C:204:57: warning: deprecated conversion from string constant to 'char*'
CGEN.C:205:42: warning: deprecated conversion from string constant to 'char*'
CGEN.C:205:42: warning: deprecated conversion from string constant to 'char*'
CGEN.C:206:42: warning: deprecated conversion from string constant to 'char*'
CGEN.C:210:35: warning: deprecated conversion from string constant to 'char*'
CGEN.C:211:26: warning: deprecated conversion from string constant to 'char*'
CGEN.C:211:26: warning: deprecated conversion from string constant to 'char*'
make: *** [cgen.o] Error 1

编译tm.c出现的问题:

$ gcc -Wall TM.C -o tm
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:96:11: warning: deprecated conversion from string constant to 'char*'
TM.C:101:11: warning: deprecated conversion from string constant to 'char*'
TM.C:101:11: warning: deprecated conversion from string constant to 'char*'
TM.C:101:11: warning: deprecated conversion from string constant to 'char*'
TM.C:101:11: warning: deprecated conversion from string constant to 'char*'
TM.C:101:11: warning: deprecated conversion from string constant to 'char*'
TM.C: In function 'int readInstructions()':
TM.C:246:47: warning: deprecated conversion from string constant to 'char*'
TM.C:249:53: warning: deprecated conversion from string constant to 'char*'
TM.C:251:49: warning: deprecated conversion from string constant to 'char*'
TM.C:253:50: warning: deprecated conversion from string constant to 'char*'
TM.C:257:13: error: no 'operator++(int)' declared for postfix '++'
TM.C:259:52: warning: deprecated conversion from string constant to 'char*'
TM.C:264:58: warning: deprecated conversion from string constant to 'char*'
TM.C:267:54: warning: deprecated conversion from string constant to 'char*'
TM.C:269:60: warning: deprecated conversion from string constant to 'char*'
TM.C:272:53: warning: deprecated conversion from string constant to 'char*'
TM.C:274:58: warning: deprecated conversion from string constant to 'char*'
TM.C:282:58: warning: deprecated conversion from string constant to 'char*'
TM.C:285:53: warning: deprecated conversion from string constant to 'char*'
TM.C:287:56: warning: deprecated conversion from string constant to 'char*'
TM.C:290:54: warning: deprecated conversion from string constant to 'char*'
TM.C:292:59: warning: deprecated conversion from string constant to 'char*'
TM.C: At global scope:
TM.C:560:31: warning: ISO C++ forbids declaration of 'main' with no type

改用github上一同学的makefile,稀里糊涂的成功编译:

makefile
#
# makefile for TINY
# Borland C Version
# K. Louden 2/3/98
#
 
CC = gcc
 
CFLAGS = -Wall
 
OBJS = main.o util.o scan.o parse.o symtab.o analyze.o code.o cgen.o
 
tiny: $(OBJS)
	$(CC) $(CFLAGS) $(OBJS) -o tiny
 
main.o: main.c globals.h util.h scan.h parse.h analyze.h cgen.h
	$(CC) $(CFLAGS) -c main.c
 
util.o: util.c util.h globals.h
	$(CC) $(CFLAGS) -c util.c
 
scan.o: scan.c scan.h util.h globals.h
	$(CC) $(CFLAGS) -c scan.c
 
parse.o: parse.c parse.h scan.h globals.h util.h
	$(CC) $(CFLAGS) -c parse.c
 
symtab.o: symtab.c symtab.h
	$(CC) $(CFLAGS) -c symtab.c
 
analyze.o: analyze.c globals.h symtab.h analyze.h
	$(CC) $(CFLAGS) -c analyze.c
 
code.o: code.c code.h globals.h
	$(CC) $(CFLAGS) -c code.c
 
cgen.o: cgen.c globals.h symtab.h code.h cgen.h
	$(CC) $(CFLAGS) -c cgen.c
 
clean:
	-rm tiny.exe
	-rm tm.exe
	-rm main.o
	-rm util.o
	-rm scan.o
	-rm parse.o
	-rm symtab.o
	-rm analyze.o
	-rm code.o
	-rm cgen.o
	-rm tm.o
 
tm: tm.c
	$(CC) $(CFLAGS) tm.c -o tm
 
all: tiny tm

编译信息:

$ make all
gcc -Wall -c main.c
main.c:48:1: warning: return type defaults to 'int'
gcc -Wall -c util.c
util.c:111:8: warning: type defaults to 'int' in declaration of 'indentno'
gcc -Wall -c scan.c
gcc -Wall -c parse.c
parse.c:23:19: warning: conflicting types for built-in function 'exp'
gcc -Wall -c symtab.c
gcc -Wall -c analyze.c
gcc -Wall -c code.c
gcc -Wall -c cgen.c
gcc -Wall main.o util.o scan.o parse.o symtab.o analyze.o code.o cgen.o -o tiny
gcc -Wall tm.c -o tm
01-基础学习/课程/编译原理/实验/tiny/gcc编译问题.txt · 最后更改: 2020/04/07 06:34 由 annhe