2011-08-20 65 views
1

當我嘗試編譯我的程序,我得到如下:Makefile的問題

**** Build of configuration Debug for project SpaceInvaders **** 

make all 
Building target: SpaceInvaders 
Invoking: GCC C++ Linker 
g++ -o "SpaceInvaders" ./src/SpaceInvaders.o -lSDLmain -lSDL 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 12 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 12 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 21 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 22 has invalid symbol index 22 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start': 
(.text+0x18): undefined reference to `main' 
collect2: ld returned 1 exit status 
make: *** [SpaceInvaders] Error 1 

**** Build Finished **** 

我認爲主要問題是建立在重定位符其中指出,搬遷1 - 20具有索引14,2,22,12和13處的無效符號。

該怎麼辦?我知道幾乎沒有任何關於makefile的知識。我看到一個潛在的重複問了相同的問題,但是調用的答案假定用戶確實知道如何使用makefile。如果任何人都能指引我走向正確的方向,那將是非常宏偉的。

回答

1

這裏的底層錯誤實際上是最後一個錯誤:'未定義的對'main'的引用。 G ++的報告方式並不完全是最好的......

您需要有一個名爲'main'的函數來啓動大多數類型的應用程序(類型不能以這種方式工作,如嵌入式或智能型,電話應用程序,將有他們自己的指示如何做相應的地方)。包含該函數的文件需要在makefile中列出。如果Eclipse正在管理makefile,那麼包含該函數的文件需要被Eclipse知道。

在這種情況下,我看到您正在使用SDL(Simple DirectMedia Layer,適用於Space Invaders等遊戲)。這是我認爲沒有簡單的用戶編寫的主應用程序的應用程序類型之一。相反,幕後會有一些低級魔法來設置一切。這個錯誤意味着魔法失敗了,然而,無論您如何配置它,它都無法組成一個完整的系統。

如果您不是Eclipse和C++的專家,您需要的是關於如何在特定環境中正確設置的教程。嘗試,例如: http://davw.nfshost.com/c/sdl_eclipse.html

我懷疑相關位是'在編譯器 - >預處理器部分,添加定義的符號「main = SDL_main」'。

+0

謝謝您的回覆。我看到你在說什麼 - 我會直接進入Eclipse創建和改變的makefile嗎?這是在C/C++中,我已經有一個主要的方法,它返回0。 – zeboidlund