DM900x移植中出現錯誤問題

樓蘭公子發表於2020-11-03
drivers/net/dm9000x.c:95:20: error: field ‘netdev’ has incomplete type
  struct eth_device netdev;
                    ^~~~~~
drivers/net/dm9000x.c: In function ‘dm9000_init’:
drivers/net/dm9000x.c:345:26: error: dereferencing pointer to incomplete type ‘struct eth_device’
  printf("MAC: %pM\n", dev->enetaddr);
                          ^~
drivers/net/dm9000x.c: In function ‘dm9000_initialize’:
drivers/net/dm9000x.c:636:2: warning: implicit declaration of function ‘eth_register’; did you mean ‘eth_receive’? [-Wimplicit-function-declaration]
  eth_register(dev);
  ^~~~~~~~~~~~

解決辦法

原因在於前向宣告類或者結構體,此時編譯器還不知道定義,無法知道類內部成員,所以無法構造例項物件,因此前向宣告的類或者結構體只能用來定義指標或者引用。

所以部分人建議定義為指標 struct eth_device *netdev;

drivers/net/dm9000x.c:345:26: error: dereferencing pointer to incomplete type ‘struct eth_device’
  printf("MAC: %pM\n", dev->enetaddr);
                          ^~
drivers/net/dm9000x.c: In function ‘dm9000_initialize’:
drivers/net/dm9000x.c:625:27: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  struct eth_device *dev = &(dm9000_info.netdev);
                           ^
drivers/net/dm9000x.c:636:2: warning: implicit declaration of function ‘eth_register’; did you mean ‘eth_receive’? [-Wimplicit-function-declaration]
  eth_register(dev);
  ^~~~~~~~~~~~

解決辦法

 

 

相關文章