我在使用IDE 1.6.7的arduino M0 pro
我正在尝试初始化变量,但是出现编译错误:

Arduino : 1.6.7 (Mac OS X), Carte : "Arduino/Genuino Zero (Programming Port)"

Attention: platform.txt du cœur 'Arduino SAMD (32-bits ARM Cortex-M0+) Boards' contiens recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" dépassé, converti automatiquement en recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}". La mise a niveau de ce cœur est conseillée.
libraries/shutter_webserver/shutterWebserver.cpp.o: In function _GLOBAL__sub_I__ZN16ShutterWebserverC2Ev':
/Users/pyrotecnix/Documents/Arduino/libraries/shutter_webserver/shutterWebserver.cpp:29: undefined reference to `ShutterWebserver::_handlers'
collect2: error: ld returned 1 exit status
exit status 1
Erreur lors de la compilation.


shutterWebserver.h

#ifndef ShutterWebserver_h
#define ShutterWebserver_h

#include <pins_arduino.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Flash.h>
#include <TinyWebServer.h>

class ShutterWebserver {

  public:

    /*Constructeur*/
    ShutterWebserver();

    static void init();
    static void run();
    static boolean index_handler(TinyWebServer& web_server);

  private:
    static TinyWebServer::PathHandler _handlers[2];
    static TinyWebServer _web;


};
#endif


shutterWebserver.cpp

#include "shutterWebserver.h"


ShutterWebserver::ShutterWebserver() {}

TinyWebServer::PathHandler _handlers[] = {
    //Register the index_handler for GET requests on /
    {"/", TinyWebServer::GET, &ShutterWebserver::index_handler },
    {NULL}, // The array has to be NULL terminated this way
};
TinyWebServer ShutterWebserver::_web = TinyWebServer(_handlers, NULL);

boolean ShutterWebserver::index_handler(TinyWebServer& web_server) {
  web_server.send_error_code(200);
  web_server << F("<html><body><h1>Hello World!</h1></body></html>\n");
  return true;
}

void ShutterWebserver::init() {
}

void ShutterWebserver::run() {
}

最佳答案

您将必须定义_handlers

TinyWebServer::PathHandler ShutterWebserver::_handlers[]


代替

TinyWebServer::PathHandler _handlers[]


shutterWebserver.cpp中。

10-08 04:09