[問題] 在連結時出錯

作者: wei115 (ㄎㄎ)   2018-03-19 02:04:03
開發平台(Platform): (Ex: Win10, Linux, ...)
win10 + MSYS2
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
mingw
問題(Question):
我用C語言寫了一個遊戲
而我想挑戰只用編輯器和make來完成
程式編譯通過了(.o檔)
但卻在連結時出了問題
像這樣 https://i.imgur.com/lO4mEoq.jpg
程式架構大概像這樣
我在.h檔中宣告了所有函數
在a.c中使用這些函數,而這些函數則定義在b.c中
而我覺得原因可能有兩種
1.我對C語言不夠熟悉,可能需要加些關鍵字告訴編譯器要如何連結
2.我剛從Google學來寫的make有問題
我覺得2的可能性比較大
想問問看大大們有什麼看法,謝謝
餵入的資料(Input):
原始檔
預期的正確結果(Expected Output):
執行檔
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
補充說明(Supplement):
Makefile
CC = gcc
game: main.o snake.o draw.o scenes.o init.o linkedlist.o os_func.o sna.h
$(CC) -o game main.o snake.o draw.o scenes.o init.o linkedlist.o os_fu
nc.o
%.o: %.c sna.h
$(CC) -c $<
clean:
rm -f *.out *.exe *o
作者: Lipraxde (Lipraxde)   2018-03-19 08:24:00
有些版本的gcc在連結的時候會受到輸入檔案順序的影響,前面的.o眼睛看不到後面的...不知道為什麼clean 那裡*o是不是要寫*.o?game 那邊可以寫$(CC) $^ -o game.exe
作者: descent (「雄辯是銀,沉默是金」)   2018-03-19 09:26:00
你有用到除了 c library 之外的其他 library 嗎?
作者: carylorrk (carylorrk)   2018-03-19 10:07:00
L大說的是 link library 時才會出現的問題,可以參考https://goo.gl/A4jvfRhttps://goo.gl/K96CGp一般來說現在的 compiler 會找所有的 object files

Links booklink

Contact Us: admin [ a t ] ucptt.com