Arduino中的core.a(main.cpp.o)错误是什么?

我在Arduino中编写代码,突然间我收到了这个错误:

core.a(main.cpp.o): In function `main': D:\Personal\Arduino\arduino-1.0.4-windows\arduino- 1.0.4\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to `setup' D:\Personal\Arduino\arduino-1.0.4-windows\arduino-1.0.4\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop' 

我不知道这意味着什么。 这是我的代码:

 #ifndef dht_h #define dht_h #if ARDUINO < 100 #include  #else #include  #endif #define DHT_LIB_VERSION "0.1.05" #define DHTLIB_OK 0 #define DHTLIB_ERROR_CHECKSUM -1 #define DHTLIB_ERROR_TIMEOUT -2 #define DHTLIB_INVALID_VALUE -999 #include  #define TIMEOUT 10000 class dht { public: int read22(uint8_t pin); double humidity; double temperature; private: uint8_t bits[5]; // Buffer to receive data int read(uint8_t pin); }; #endif // return values: // DHTLIB_OK // DHTLIB_ERROR_CHECKSUM // DHTLIB_ERROR_TIMEOUT int dht::read22(uint8_t pin) { // READ VALUES int rv = read(pin); if (rv != DHTLIB_OK) { humidity = DHTLIB_INVALID_VALUE; // Invalid value, or is NaN prefered? temperature = DHTLIB_INVALID_VALUE; // Invalid value return rv; } // CONVERT AND STORE humidity = word(bits[0], bits[1]) * 0.1; if (bits[2] & 0x80) // negative temperature { temperature = word(bits[2]&0x7F, bits[3]) * 0.1; temperature *= -1.0; } else { temperature = word(bits[2], bits[3]) * 0.1; } // TEST CHECKSUM uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3]; if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; return DHTLIB_OK; } //Private // return values: // DHTLIB_OK // DHTLIB_ERROR_TIMEOUT int dht::read(uint8_t pin) { // INIT BUFFERVAR TO RECEIVE DATA uint8_t cnt = 7; uint8_t idx = 0; // EMPTY BUFFER for (int i=0; i 5 BYTES for (int i=0; i 40) bits[idx] |= (1 << cnt); if (cnt == 0) // Next byte? { cnt = 7; idx++; } else cnt--; } return DHTLIB_OK; } 

我需要做些什么来修复此代码?

每个Arduino程序都需要函数setup()loop() ,你没有它们。

你可能应该看看这个 。

您应该将它们添加到主文件中(通常是您在IDE中创建的第一个文件)。