1. 程式人生 > >Makefile 編譯生成多個可執行檔案

Makefile 編譯生成多個可執行檔案

all:server client

server:server.c

gcc $< -o [email protected]

client:client.c

gcc $< -o [email protected]

clean:

    rm -f server

    rm -f client

解釋:

[email protected] ——目標檔案的名稱;
(2) $^ ——所有的依賴檔案,以空格分開,不包含重複的依賴檔案;
(3) $< ——第一個依賴檔案的名稱。

示例:
main:main.c sort.o
gcc main.c sort.o -o main
表示為簡潔的就是:
main:main.c sort.o
gcc $^ -o

[email protected]