我的 makefile 与 gcc 编译器有问题。如果我直接使用 gcc:
gcc -std=c99 -lm tm.c tm_coins.c tm_options.c tm_stock.c tm_utility.c -o tm -Wall -pedantic
一切正常。我需要-std-c99 和-lm。
但是,我被告知要使用 makefile。这是我的制作文件:
CFLAGS=-ansi -Wall -pedantic
LFLAGS=-std=c99 -lm
CC=gcc
all:tm
tm:tm.o tm_coins.o tm_options.o tm_stock.o tm_utility.o
$(CC) $(LFLAGS) tm.o tm_coins.o tm_options.o tm_stock.o tm_utility.o -o tm $(CFLAGS)
tm.o: tm.h tm.c
$(CC) $(LFLAGS) $(CFLAGS) -c tm.c
tm_coins.o:tm_coins.h tm_coins.c
$(CC) $(LFLAGS) $(CFLAGS) -c tm_coins.c
tm_options:tm_options.h tm_options.c
$(CC) $(LFLAGS) $(CFLAGS) -c tm_options.c
tm_stock:tm_stock.h tm_stock.c
$(CC) $(LFLAGS) $(CFLAGS) -c tm_stock.c
tm_utility:tm_utility.h tm_utility.c
$(CC) $(LFLAGS) $(CFLAGS) -c tm_utility.c
使用上面的makefile,我得到以下错误。我的理解是 -std=c99 和 -lm 不起作用。(看看下面的第一行。-std=c99 和 -lm 不存在)
gcc -ansi -Wall -pedantic -c -o tm_options.o tm_options.c
tm_options.c: In function ‘purchase_ticket’:
tm_options.c:37: error: expected expression before ‘/’ token
tm_options.c:52: error: expected expression before ‘/’ token
tm_options.c:102: warning: ISO C90 forbids mixed declarations and code
tm_options.c: In function ‘display_tickets’:
tm_options.c:239: error: expected expression before ‘/’ token
tm_options.c: In function ‘add_ticket’:
tm_options.c:285: error: expected expression before ‘/’ token
tm_options.c:303: error: expected expression before ‘/’ token
tm_options.c:314: warning: ISO C90 forbids mixed declarations and code
tm_options.c: In function ‘delete_ticket’:
tm_options.c:387: error: expected expression before ‘/’ token
tm_options.c:405: error: expected expression before ‘/’ token
tm_options.c: In function ‘display_coins’:
tm_options.c:461: error: expected expression before ‘/’ token
tm_options.c: In function ‘restock_tickets’:
tm_options.c:501: error: expected expression before ‘/’ token
tm_options.c: In function ‘restock_coins’:
tm_options.c:526: error: expected expression before ‘/’ token
tm_options.c: In function ‘save_data’:
tm_options.c:555: warning: ISO C90 forbids mixed declarations and code
错误会在哪里?提前致谢。