[英]is it necessary to have same names for .c and .o files?
CC=gcc -Wall
CFLAGS = -Wno-pointer-sign
LDFLAGS= -lipq
all: mtu rtu obj
mtu: flexiBitw_mtu
rtu: flexiBitw_rtu
flexiBitw_mtu: packetCapture.o mtu_decodePkt.o encrypt_decrypt.o sha1.o crypt.o file_parse.o
$(CC) $(CFLAGS) packetCapture.o mtu_decodePkt.o encrypt_decrypt.o sha1.o crypt.o file_parse.o -o flexiBitw_mtu $(LDFLAGS)
flexiBitw_rtu: packetCapture.o rtu_decodePkt.o encrypt_decrypt.o sha1.o crypt.o file_parse.o
$(CC) $(CFLAGS) packetCapture.o rtu_decodePkt.o encrypt_decrypt.o sha1.o crypt.o file_parse.o -o flexiBitw_rtu $(LDFLAGS)
obj:
rm -f *.o
packetCapture.o: packetCapture.c
$(CC) $(CFLAGS) -c packetCapture.c file_parse.c
mtu_decodePkt.o: mtu_decodePkt.c
$(CC) $(CFLAGS) -DCOMPILE_MTU -c mtu_decodePkt.c
rtu_decodePkt.o: mtu_decodePkt.c
$(CC) $(CFLAGS) -DCOMPILE_RTU -c mtu_decodePkt.c
encrypt_decrypt.o: encrypt_decrypt.c sha1.c crypt.c
$(CC) $(CFLAGS) -c encrypt_decrypt.c sha1.c crypt.c
clean:
rm -rf *.o flexiBitw_mtu
rm -rf *.o flexiBitw_rtu
它給出的輸出為:
gcc -Wall -Wno-pointer-sign -c packetCapture.c file_parse.c
gcc -Wall -Wno-pointer-sign -DCOMPILE_MTU -c mtu_decodePkt.c
gcc -Wall -Wno-pointer-sign -c encrypt_decrypt.c sha1.c crypt.c
gcc -Wall -Wno-pointer-sign packetCapture.o mtu_decodePkt.o encrypt_decrypt.o sha1.o crypt.o file_parse.o -o flexiBitw_mtu -lipq
gcc -Wall -Wno-pointer-sign -DCOMPILE_RTU -c mtu_decodePkt.c
gcc -Wall -Wno-pointer-sign packetCapture.o rtu_decodePkt.o encrypt_decrypt.o sha1.o crypt.o file_parse.o -o flexiBitw_rtu -lipq
gcc: rtu_decodePkt.o: No such file or directory
make: *** [flexiBitw_rtu] Error 1
我通過在mtu_decodepkt.c文件中啟用不同的宏來進行條件編譯,但是它給出錯誤rtu_decodePkt.o:沒有這樣的文件或目錄。 我必須更改.o文件名,以使其在制作兩個可執行文件時不重合。
請回復 ...
您需要告訴編譯器您希望對象文件被調用什么:
rtu_decodePkt.o: mtu_decodePkt.c
$(CC) $(CFLAGS) -DCOMPILE_RTU -c mtu_decodePkt.c -o rtu_decodePkt.o
^^^^^^^^^^^^^^^^^^
不,沒有必要。 您可以使用GCC的-o
選項指定目標文件的名稱,並根據需要鏈接.o文件。
但是在那種情況下,您一次只能編譯一個.c
文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.