天天看點

arduino寫自定義庫檔案報錯解決not name of type、not declared in this scope

第一次嘗試寫arduino庫檔案,沒想到就是編譯不通過。

現總結一下容易錯誤的地方。

一般我們是在arduino/libraries目錄下建立我們自己的庫檔案目錄和檔案。但要注意的是libraries目錄預設是隻讀的。

建立好庫之後,我們該去使用它了,我們打開arduino開始寫應用程式,導入我們自定義的庫時,我們在libraries目錄下的庫會自動拷貝一份到我們工程檔案夾中。

那麼問題來了,當我們寫的庫檔案有錯誤需要修改時,我們修改libraries目錄下的庫檔案時,工程目錄下的庫檔案并沒有被修改到,是以依然頑固的編譯不通過。這種情況解決辦法就是修改工程目錄下的庫檔案即可。

編譯器一直報  變量沒有被聲明,原因是庫檔案沒有被包含或者是庫檔案确實有文法錯誤。

does not name of type

xxx was not declared in this scope

 This report would have more information with

  "Show verbose output during compilation"

  enabled in File > Preferences.

Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"

sketch_dec23a:6: error: 'LightClass' does not name a type

sketch_dec23a.ino: In function 'void setup()':

sketch_dec23a:12: error: 'light' was not declared in this scope

sketch_dec23a.ino: In function 'void loop()':

sketch_dec23a:17: error: 'light' was not declared in this scope

繼續閱讀