2017-06-19 128 views
0

我正在使用這個code我在github上找到了。 爲了使用uspi庫,幫助文檔(USING SECTION)說我應該創建一個makefile並在那裏指定includes和libraries文件。 因爲我是新來的Makefile的概念,我第一次嘗試這樣做手工鍵入:arm gcc linker undefined reference

arm-linux-gnueabihf-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -std=c99 -I./uspi/env/include -I./uspi/include -L./uspi/lib -luspi w.o -o kernel.elf 

這樣的錯誤出現:

w.o: In function `main': 
w.c:(.text+0xc): undefined reference to `USPiEnvInitialize' 
w.c:(.text+0x24): undefined reference to `USPiInitialize' 
w.c:(.text+0x48): undefined reference to `LogWrite' 
w.c:(.text+0x4c): undefined reference to `USPiEnvClose' 
w.c:(.text+0x58): undefined reference to `USPiMassStorageDeviceAvailable' 
w.c:(.text+0x80): undefined reference to `LogWrite' 
w.c:(.text+0x84): undefined reference to `USPiEnvClose' 
w.c:(.text+0xb8): undefined reference to `USPiMassStorageDeviceRead' 
w.c:(.text+0xdc): undefined reference to `LogWrite' 
w.c:(.text+0x108): undefined reference to `LogWrite' 
w.c:(.text+0x124): undefined reference to `LogWrite' 
w.c:(.text+0x13c): undefined reference to `LogWrite' 
w.c:(.text+0x204): undefined reference to `LogWrite' 
w.c:(.text+0x23c): undefined reference to `USPiEnvClose' 
collect2: error: ld returned 1 exit status 

我需要的.elf文件,這樣我就可以產生。 IMG文件從它

+0

如果你在'w.o'之後加上'-luspi'? (請注意,您需要自己實現在uspios.h中聲明的函數,例如LogWrite) – nos

+0

沒有運氣我的朋友,同樣的錯誤 – sami

+1

我不相信你。如果您仍然對未定義的參考USPiEnvClose,有些事情是錯誤的,我們沒有任何有關信息。庫本身是否正確構建,(你會得到一個未定義的引用LogWrite(),直到你實現它) – nos

回答

1

此鏈接順序:

arm-linux-gnueabihf-gcc ... -luspi w.o -o kernel.elf 

不正確。圖書館應遵循他們從引用的對象:

arm-linux-gnueabihf-gcc ... w.o -luspi -o kernel.elf 

Explanation