Hi I am just getting started with Platform ide and I found this error while trying to build esp32 project
c:/users/salah/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\libFrameworkArduino.a(main.cpp.o):(.literal._Z8loopTaskPv+0x8): undefined reference to setup()' c:/users/salah/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\libFrameworkArduino.a(main.cpp.o):(.literal._Z8loopTaskPv+0xc): undefined reference to
loop()’
c:/users/salah/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\libFrameworkArduino.a(main.cpp.o): in function loopTask(void*)': C:/Users/Salah/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:42: undefined reference to
setup()’
c:/users/salah/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: C:/Users/Salah/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:48: undefined reference to `setup()’
Without providing your code it’s impossible that we know what is going on.
I am trying to scan for available ble devices ,this is the code :
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
// Not used here since we’re performing scanning in the loop
}
BLEScan* pBLEScan;
void setup() {
Serial.begin(115200);
BLEDevice::init(“ESP32 Scanner”);
pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
}
void loop() {
BLEScanResults foundDevices = pBLEScan->start(5); // Scan for 5 seconds
for (int i = 0; i < foundDevices.getCount(); i++) {
BLEAdvertisedDevice device = foundDevices.getDevice(i);
Serial.print("Found BLE Device: ");
Serial.print("Name: ");
Serial.print(device.getName().c_str()); // Convert to C-style string
Serial.print(", MAC: ");
Serial.print(device.getAddress().toString().c_str()); // Convert to C-style string
Serial.print(", RSSI: ");
Serial.print(device.getRSSI());
if (device.haveManufacturerData()) {
std::string manufacturerData = device.getManufacturerData();
Serial.print(", Data: ");
for (size_t j = 0; j < manufacturerData.size(); j++) {
Serial.printf("%02X ", manufacturerData[j]);
}
}
Serial.println();
}
delay(5000); // Wait for 5 seconds before scanning again
}
};
platform.ini
[env:esp32dev]
platform = espressif32
board = nodemcu-32s
framework = arduino
lib_deps = armmbed/ble@^2.7.0
Format your code and you’ll see the misplaced right brace. You are declaring setup()
and loop()
in the MyAdvertisedDeviceCallbacks
class. They need to be global.
thank you sir ,that was a stupid mistake