2016-08-19 52 views
0

我使用MinGW和試圖建立一個使用Makefile證明可執行文件,但它給了我下面的錯誤GCC:說到這個如此Makefile文件上對C

Directory of C:\Users\PATTY\Desktop\loops 

08/19/2016 01:34 PM <DIR>   . 
08/19/2016 01:34 PM <DIR>   .. 
08/18/2016 10:41 PM   59,628 a.exe 
08/18/2016 11:58 PM    261 demo.c 
08/18/2016 11:59 PM   59,541 demo.exe 
08/18/2016 07:01 PM    605 justify.c 
08/18/2016 07:01 PM    1,122 line.c 
08/18/2016 07:02 PM    197 line.h 
08/19/2016 01:03 AM    350 newquote.txt 
08/18/2016 11:05 PM    628 planets.c 
08/18/2016 11:14 PM   60,139 planets.exe 
07/15/2016 08:03 PM    89 pun.c 
08/19/2016 12:55 AM    412 quote.txt 
08/13/2016 05:32 PM    167 reverse.c 
08/18/2016 10:45 PM   28,107 reverse.exe 
08/18/2016 10:45 PM    708 reverse.o 
08/19/2016 03:14 AM    459 something.txt 
08/11/2016 11:14 PM    1,698 test.c 
08/18/2016 07:01 PM    427 word.c 
08/18/2016 07:02 PM    92 word.h 
       18 File(s)  214,630 bytes 
       2 Dir(s) 164,884,508,672 bytes free 

C:\Users\PATTY\Desktop\loops>mingw32-make justify 
cc  justify.c -o justify 
process_begin: CreateProcess(NULL, cc justify.c -o justify, ...) failed. 
make (e=2): The system cannot find the file specified. 
<builtin>: recipe for target 'justify' failed 
mingw32-make: *** [justify] Error 2 

C:\Users\PATTY\Desktop\loops> 

我是初學者,請讓我知道我錯過了什麼或做錯了什麼。

編輯:

另一個失敗的嘗試:

C:\Users\PATTY\Desktop\loops>mingw32-make justify CC=gcc 
gcc  justify.c -o justify 
C:\Users\PATTY\AppData\Local\Temp\cc2z2lvl.o:justify.c:(.text+0x10): undefined reference to `clear_line' 
C:\Users\PATTY\AppData\Local\Temp\cc2z2lvl.o:justify.c:(.text+0x24): undefined reference to `read_word' 
C:\Users\PATTY\AppData\Local\Temp\cc2z2lvl.o:justify.c:(.text+0x40): undefined reference to `flush_line' 
C:\Users\PATTY\AppData\Local\Temp\cc2z2lvl.o:justify.c:(.text+0x5f): undefined reference to `space_remainding' 
C:\Users\PATTY\AppData\Local\Temp\cc2z2lvl.o:justify.c:(.text+0x68): undefined reference to `write_line' 
C:\Users\PATTY\AppData\Local\Temp\cc2z2lvl.o:justify.c:(.text+0x6d): undefined reference to `clear_line' 
C:\Users\PATTY\AppData\Local\Temp\cc2z2lvl.o:justify.c:(.text+0x79): undefined reference to `add_word' 
collect2.exe: error: ld returned 1 exit status 
<builtin>: recipe for target 'justify' failed 
mingw32-make: *** [justify] Error 1 

C:\Users\PATTY\Desktop\loops> 
+0

圖片的問題是沒用的。您的代碼和錯誤消息是文本。剪切/粘貼到你的問題。 –

+0

我只是不知道如何複製/粘貼打印在cmd提示符上的文本 – tadm123

+0

將包含mingw-make.exe的文件夾添加到Path環境變量中,關閉終端,再次打開並重試。 – Tim

回答

2

I'm using MinGW and trying to create a justify executable using the Makefile

不,你不是。 make命令:

C:\Users\PATTY\Desktop\loops>mingw32-make justify 

沒有指定任何makefile。在這種情況下,make將在工作目錄中默認爲 for makefile,如果失敗,將在工作目錄中查找 Makefile。但C:\Users\PATTY\Desktop\loops 的目錄列表顯示這兩個makefile都不存在。

在這種情況下,make倒在其內置的規則數據庫,看看 如果任何人可能讓它從文件建立目標justify是 存在於工作目錄,在沒有任何規定或違約makefile文件。

它發現這個內置的規則:

%: %.c 
    $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o [email protected] 

這將嘗試編譯並從單一 匹配的C源文件%.c鏈接目標匹配%

此規則匹配目標justify和源文件justify.c。這 源文件在工作目錄中存在,所以make試圖配方:

$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o [email protected] 

與前提$^ = justify.c和目標[email protected] = justify

但它不變量的全展後,因爲工作,配方變爲:

cc  justify.c -o justify 

其中cc是化妝雜物的默認值表示C編譯器。 這是因爲$(LINK.c)定義:

LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 

你在你的PATH有沒有這樣的計劃爲cc,使配方失敗:

process_begin: CreateProcess(NULL, cc justify.c -o justify, ...) failed. 
make (e=2): The system cannot find the file specified. 

你意識到這是問題的本質,並嘗試:

C:\Users\PATTY\Desktop\loops>mingw32-make justify CC=gcc 

這樣的程序作爲01你的PATH中的,它是你的C編譯器。 這是更好的,但是內置的配方,現在擴展爲:

gcc  justify.c -o justify 

這將嘗試編譯並從單一 源文件justify.c鏈接程序justify。而作爲you know, 你需要在這個目錄下建立這個程序的配方是:

gcc -o justify justify.c line.c word.c 

所以你現在正在運行的配方失敗,你已經注意到,因爲 你不編譯或鏈接源鏈接錯誤其中缺少的功能定義爲 的文件。

如果你想建立正確使用make程序,你需要學習 書寫makefile文件的要領,然後寫一個指示make打造 程序正確。您可以將此生成文件保存爲C:\Users\PATTY\Desktop\loops ,因爲makefileMakefilemake將默認使用它。或者你可以 叫它任何你喜歡的,並通過名稱與-f選項來指定它,當你調用make

mingw32-make -f whatever.mak ... 

Here is a fairly sound beginner's tutorial for using GCC with GNU make。 權威文檔,here is the GCC manualhere is the GNU Make manual