我在使用gcc編譯器時遇到了我的makefile問題。如果我直接使用gcc:GCC makefile不接受-std = c99 -lm
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。這裏是我的make文件:
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
哪裏會出錯?提前致謝。
感謝Magnus。你對.o擴展名是正確的。它解決了一半的問題。保羅解決了另一半。我不知道如何拆分答案標記:) – Oscar
嘿嘿:)也許這次誤會添加答案標記:P我很高興你的幫助:) –
你說的對。謝謝保羅。案例關閉:) – Oscar