天天看點

解決undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'錯誤

自己寫裸機驅動程式時,使用了除法,在連結的時候出了如下錯誤:  

解決undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'錯誤

  使用的編譯器是:  

解決undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'錯誤

  後來上網搜了一下原因,由于編譯器不支援除法運算,但是也沒有搜到解決方案。看了一下代碼确實用到了除法,把除法去掉可以正常連接配接通過。後來想了想了,之前編譯核心和編譯u_boot都是這個編譯器的呀,他們肯定有除法運算呀,他們是怎麼做到的呢? 于是看了一下u_boot的Makefile,很暈,東西很多,後來編譯了一下,看到了這個:  

解決undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'錯誤

  u_boot在連結的時候,指定了黃色顔色的路徑和-lgcc選項(-l後面的是連結庫的名字)

到指定的目錄下看到如下内容:  

解決undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'錯誤

  裡面有一個libgcc.a的靜态庫,編譯器支援軟浮點,猜想軟浮點的實作應該就是在找個靜态庫中。 在自己的Makefile裡面加上了這些東西,繼續編譯連接配接出現如下錯誤資訊:  

解決undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'錯誤

  缺少"raise符号",在u_boot源碼中搜尋"raise"如下:  

解決undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'錯誤

是一個函數,什麼也沒幹,我在自己的代碼中寫了一個這樣的空函數,編譯通過。

Makefile 如下:  

解決undefined reference to `__aeabi_uidivmod'和undefined reference to `__aeabi_uidiv'錯誤

    總結:     ARMv4t的ARM核不支援浮點運算,為了讓其支援浮點運算,編譯器使用了軟浮點的方法,但是需要相應的除法庫支援,在連接配接的時候需要指定其路徑和庫名。

    一句經典名言: 在IT行業,遇到問題,隻要一直解決,總有解決的一天。