![](/img/trans.png)
[英]compile with -ansi -pedantic -Wall switches automatically with gcc
[英]gcc makefile with -Wall -pedantic and -lpthread
我試圖從模板制作一個makefile,這就是我得到的:
CFLAGS = -Wall -pedantic
LFLAGS = -lpthread
CC = gcc
OBJS = bank5.o client2.o
PROGRAM = ex2
all: bank client
ex2: $(OBJS)
$(CC) $(LFLAGS) $(OBJS) -o $(PROGRAM)
bank: bank5.c
$(CC) $(CFLAGS) -c bank5.c receive_message.c send_message.c -o bank5
client: client2.c
$(CC) $(CFLAGS) -c client2.c receive_message.c send_message.c -o client2
當我嘗試運行它時,出現此錯誤:
gcc -Wall -pedantic -c bank5.c receive_message.c send_message.c -o bank5
gcc: fatal error: cannot specify -o with -c, -S or -E with multiple files
compilation terminated.
make: *** [bank] Error 4
這是我的makefile在-Wall和-pedantic之前的樣子,正常運行:
all: bank client
bank: bank5.c
gcc bank5.c receive_message.c send_message.c -o bank5 -lpthread
client: client2.c
gcc -o client2 client2.c send_message.c receive_message.c
-c
只會編譯每個文件(即生成一個目標文件),而不是將它們鏈接在一起。 因為一個目標文件對應一個源文件,所以將創建多個目標文件 。
-o
指定一個輸出文件。
顯然,兩者相互矛盾。
刪除-c
以解決問題。
無論如何,您的makefile看起來很壞。 ex2
在那做什么? bank5.o
和client2.o
任何地方創建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.