2014-10-10 31 views
1

所以我的任務基本上要求做一個Makefile來將sorted-list.c實現編譯到名爲libsl.a的庫中,並且一個名爲sl的可執行文件運行代碼在main.c中。基本的makefile /鏈接/庫的問題:沒有這樣的文件或目錄

所以我迄今寫:

cc=gcc 

sl : main.o sorted-list.o 
    cc -o -g sl main.o sorted-list.o 

main.o : main.c sorted-list.h 
sorted-list.o : sorted-list.c sorted-list.h 

ar : rcs libsl.a sorted-list.o 

clean : 
    rm sl main.o sorted-list.o 

在包含我的所有文件,以及文件makefile文件的目錄,我輸入到終端:

make 

現在,這是我第一次做所有這些,所以我只能假定它已經按照我的意圖執行了。如果沒有,請讓我知道。話雖這麼說,我得到以下錯誤:

-bash-4.1$ make 
cc -c -o sorted-list.o sorted-list.c 
cc -o -g sl main.o sorted-list.o 
cc: sl: No such file or directory 
make: *** [sl] Error 1 

#2有以下問題:
Makefile is giving me an error - No such file or directory

這似乎是最接近的問題/解決方案,但我可執行SL似乎被放置正確的(直接在旗幟之後),如答案所示。我不確定這是否重要,但我沒有任何名爲sl的提交/目錄 - 根據我的理解,這將是尚未創建的可執行文件的名稱。

回答

0

您必須將可執行文件的名稱緊接在-o選項後面,因爲它是此選項的參數。所以

cc -g -o sl main.o sorted-list.o 

,而不是

cc -o -g sl main.o sorted-list.o 

cc(1)的手冊頁應該讀這樣的事情:

 
-o output 
    Name the output of the compilation output instead of a.out. 

這表明你的可執行文件的名稱是一個參數來-o選項因此必須在-o選項後立即出現。

有關更多詳細信息,請閱讀手冊cc(1)

相關問題