PlatformIO致命构建错误:LiquidCrystal.h"没有这样的文件或目录"

时间:2017-10-31 07:24:56

标签: build compiler-errors arduino platformio esp32

我是Atom / PlatformIO的新手,并尝试使用Arduino作为Arduino IDE的替代品进行开发。

〜规格〜

base code used: Arduino ESP sample code "WifiBlueToothSwitch.ino"
Board: ESP-WROOM-32
Additional Components: 1602A (2x16) LCD

在尝试使用LCD屏幕之前,我已经通过PlatformIO在ESP模块上成功运行了其他示例代码,但是当我尝试包含LiquidCrystal.h库时,它给了我一个构建错误:

src\main.cpp:22:27: fatal error: LiquidCrystal.h: No such file or directory
compilation terminated.
*** [.pioenvs\esp32dev\src\main.o] Error 1
[ERROR] Took 3.34 seconds

到目前为止,我已经搜索过几个关于这个问题的网站,大多数网站指的是缺少添加" wire.h"头文件,但即使将其包含在程序中,它仍然会给我这个错误。

我的内容如下:

#include <Arduino.h>
#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal.h>

所以我不完全确定为什么会出现这个问题。 我该如何解决这个问题?

编辑1:

我刚刚遇到另一个网站建议尝试通过控制台更新PlatformIO,但这无济于事。一切都被标记为&#34;最新的&#34;。

Documents\PlatformIO\Projects\171031-143050-esp32dev> platformio update
Updating tool-scons                      @ 3.20501.2      [Up-to-date]
Updating tool-unity                      @ 1.20302.1      [Up-to-date]
Updating pysite-pioplus                  @ 0.4.2          [Up-to-date]
Updating contrib-piohome                 @ 0.3.1          [Up-to-date]
Updating tool-pioplus                    @ 0.10.11        [Up-to-date]

Platform Manager
================
Platform Espressif 32
--------
Updating espressif32                     @ 0.10.0         [Up-to-date]

Updating tool-esptoolpy                  @ 1.20000.0      [Up-to-date]
Updating toolchain-xtensa32              @ 1.50200.0      [Up-to-date]
Updating framework-arduinoespressif32    @ 1.2.0          [Up-to-date]
Updating tool-espotapy                   @ 1.0.0          [Up-to-date]


Library Manager
===============
Documents\PlatformIO\Projects\171031-143050-esp32dev>

编辑2:

已经编译并通过Arduino IDE运行此代码并且可以确认它是否有效,因此问题似乎与PlatformIO IDE有关......

编辑3:

在遵循BMelis的建议后,我查看了PlatformIO.ini文件,并在其中添加了以下行:

lib_extra_dirs = C:\Program Files (x86)\Arduino\hardware\espressif\esp32\libraries

这修复了LiquidCrystal.h的初始错误,但是这在构建期间也产生了以下依赖性错误:

[11/06/17 08:52:58] Processing esp32dev (platform: espressif32; lib_extra_dirs: C:\Program Files (x86)\Arduino\hardware\espressif\esp32\libraries; board: esp32dev; framework: arduino)

Verbose mode can be enabled via `-v, --verbose` option
Collected 49 compatible libraries
Looking for dependencies...
Library Dependency Graph
|-- <WiFi> v1.0

|-- <Wire> v1.0
|-- <LiquidCrystal> v1.0.7
Compiling .pioenvs\esp32dev\lib\WiFi\WiFiAP.o
Compiling .pioenvs\esp32dev\lib\WiFi\WiFiGeneric.o
Compiling .pioenvs\esp32dev\lib\WiFi\WiFiMulti.o
Compiling .pioenvs\esp32dev\lib\WiFi\WiFiSTA.o

****ERROR OCCURRED****
C:\Program Files (x86)\Arduino\hardware\espressif\esp32\libraries\WiFi\src\WiFiAP.cpp:40:37: fatal error: apps/dhcpserver_options.h: No such file or directory
compilation terminated.
*** [.pioenvs\esp32dev\lib\WiFi\WiFiAP.o] Error 1
 [ERROR] Took 8.13 seconds

我尝试在ini文件中添加第二个lib_extra_dirs命令来添加它提到的目录:

lib_extra_dirs = C:\Program Files (x86)\Arduino\hardware\espressif\esp32\tools\sdk\include\lwip\apps

然而,这没有解决问题。我现在不知道该做什么......

完整代码:

#include <Arduino.h>
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Sketch shows how to switch between WiFi and BlueTooth or use both
// Button is attached between GPIO 0 and GND and modes are switched with each press

#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#define STA_SSID "HIDDEN FOR SECURITY"
#define STA_PASS "HIDDEN FOR SECURITY"
#define AP_SSID  "esp32 @ my desk"
#define LED_PIN  5

//LCD variables on analog inputs, but used as digital I/O
//lcd_gnd = gnd
//lcd_vcc = +5v
//lcd_v0 = +5v & pot
const int lcd_rs = 27;
//lcd_rw = gnd
const int lcd_e = 14;
//lcd_d0 = n/a
//lcd_d1 = n/a
//lcd_d2 = n/a
//lcd_d3 = n/a
const int lcd_d4 = 32;
const int lcd_d5 = 33;
const int lcd_d6 = 25;
const int lcd_d7 = 26;
//lcd_bl1 = +5v
//lcd_bl2 = gnd
LiquidCrystal lcd(lcd_rs, lcd_e, lcd_d4, lcd_d5, lcd_d6, lcd_d7);

enum { STEP_BTON, STEP_BTOFF, STEP_STA, STEP_AP, STEP_AP_STA, STEP_OFF, STEP_BT_STA, STEP_END };

void onButton(){
  static uint32_t step = STEP_BTON;
  switch(step){
    case STEP_BTON://BT Only
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Starting BT");
      btStart();
    break;
    case STEP_BTOFF://All Off
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Stopping BT");
      btStop();
    break;
    case STEP_STA://STA Only
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Starting STA");
      WiFi.begin(STA_SSID, STA_PASS);
    break;
    case STEP_AP://AP Only
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Stopping STA");
      WiFi.mode(WIFI_AP);

      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Starting AP");
      WiFi.softAP(AP_SSID);
    break;
    case STEP_AP_STA://AP+STA
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Starting STA");
      WiFi.begin(STA_SSID, STA_PASS);
    break;
    case STEP_OFF://All Off
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Stopping WiFi");
      WiFi.mode(WIFI_OFF);
    break;
    case STEP_BT_STA://BT+STA
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Starting STA+BT");
      WiFi.begin(STA_SSID, STA_PASS);
      btStart();
    break;
    case STEP_END://All Off
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Stopping WiFi+BT");
      WiFi.mode(WIFI_OFF);
      btStop();
    break;
    default:
    break;
  }
  if(step == STEP_END){
    step = STEP_BTON;
  } else {
    step++;
  }
  //little debounce
  delay(100);
}

void WiFiEvent(WiFiEvent_t event){
    switch(event) {
        case SYSTEM_EVENT_AP_START:
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("AP Started");
            Serial.print("AP Started");
            WiFi.softAPsetHostname(AP_SSID);
            break;
        case SYSTEM_EVENT_AP_STOP:
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("AP Stopped");
            Serial.print("AP Stopped");
            break;
        case SYSTEM_EVENT_STA_START:
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("STA Started");
            Serial.print("STA Started");
            WiFi.setHostname(AP_SSID);
            break;
        case SYSTEM_EVENT_STA_CONNECTED:
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("STA Connected");
            Serial.print("STA Connected");
            WiFi.enableIpV6();
            break;
        case SYSTEM_EVENT_AP_STA_GOT_IP6:
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("STA IPv6: ");
            Serial.print("STA IPv6: ");
            Serial.println(WiFi.localIPv6());
            break;
        case SYSTEM_EVENT_STA_GOT_IP:
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("STA IPv4: ");
            Serial.print("STA IPv4: ");
            lcd.setCursor(0,1);
            lcd.print(WiFi.localIP());
            Serial.print(WiFi.localIP());
            break;
        case SYSTEM_EVENT_STA_DISCONNECTED:
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("STA Disconnected");
            Serial.print("STA Disconnected");
            break;
        case SYSTEM_EVENT_STA_STOP:
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("STA Stopped");
            Serial.print("STA Stopped");
            break;
        default:
            break;
    }
}

void setup() {
    lcd.begin(16, 2); //tells arduino that the LCD is a 16x2 size LCD
    lcd.clear(); //clear any previous text
    lcd.setCursor(0, 0); // set cursor to column 0 of row 0 (first row, first block)

    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW); // LED off
    Serial.begin(115200);
    pinMode(0, INPUT_PULLUP);
    WiFi.onEvent(WiFiEvent);
    Serial.print("ESP32 SDK: ");
    Serial.println(ESP.getSdkVersion());
    Serial.println("Press the button to select the next mode");
    lcd.setCursor(0, 0);
    lcd.println("Press mode btn");
}

void loop() {
    digitalWrite(LED_PIN, HIGH); // Turn on LED
    static uint8_t lastPinState = 1;
    uint8_t pinState = digitalRead(0);
    if(!pinState && lastPinState){
        onButton();
    }
    lastPinState = pinState;
}

4 个答案:

答案 0 :(得分:0)

对于platformio,我这样工作(我在Win10上): 我的所有项目都在&#34;我的文件&#34;。通用库位于&#34;我的文档/库&#34;中。具体的那些存在于&#34; lib&#34; pio项目的文件夹。

在platformio.ini中,我有以下内容:

<table align="center">
  <thead>
    <tr>
      <th>Cycle Code</th>
      <th>Product</th>
      <th>Days Until Due</th>
    </tr>
  </thead>
  <tbody>
    {BEGIN*REPEAT}
    <tr>
      <td>{UDF_CYCLE}</td>
      <td>{Product}</td>
      <td><span data-daystilldue="{daystilldue}">{daystilldue}</span></td>
    </tr>
    <tr>
      <td>{UDF_CYCLE}</td>
      <td>Example 1</td>
      <td><span data-daystilldue="1">1</span></td>
    </tr>
        <tr>
      <td>{UDF_CYCLE}</td>
      <td>Example 2</td>
      <td><span data-daystilldue="0">0</span></td>
    </tr>
            <tr>
      <td>{UDF_CYCLE}</td>
      <td>Example 3</td>
      <td><span data-daystilldue="-1">-1</span></td>
    </tr>
            <tr>
      <td>{UDF_CYCLE}</td>
      <td>Example 4</td>
      <td><span data-daystilldue="-20">-20</span></td>
    </tr>
    {END*REPEAT}
  </tbody>
</table>

对于平台你可以评出正确的一个(阶段或发布但是对于Arduino ESP32&#34;发布&#34;非常......不稳定)

将正确的路径放在lib_extra_dirs中,并尝试远离隐藏&#34; Program Files&#34;中的所有库。文件夹,因为如果需要的话,在那里更改一些东西是非常不方便的。

答案 1 :(得分:0)

我认为您需要下载 LiquidCrystal 软件包,或者使用PlatformIO CLI下载它。检查一下:http://platformio.org/lib/show/887/LiquidCrystal/installation

将解压缩的LiquidCrystal文件夹复制到项目的/lib文件夹中,然后再尝试构建。

ps:私人/第三方图书馆应放置/lib文件夹。

答案 2 :(得分:0)

在终端中输入:

pio lib install "LiquidCrystal"

答案 3 :(得分:0)

我也遇到了这个问题。我认为最好的解决方案是将项目和董事会的条目添加到您的platformio.ini文件中。这样,您无需将库代码添加到自己的源代码树中,并且该解决方案可以抵御“在我的计算机上工作”,因为该项目不依赖于库在文件系统上的特定位置。请注意,我在此处针对特定版本指定了最大的可预测性,但是您不必这样做。

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
lib_deps = LiquidCrystal@1.5.0 #<--important line