A sketch using the Wire library fails to compile when using an esp32 board. AVR boards are not a problem. I've tried compiling several sketches using the wire library with the same results, so I included the simplest program possible to eliminate any other coding problems. I'm using Arduino 2.3.10 running on Windows 11. Here are the errors:
C:/Users/fkunz/AppData/Local/Arduino15/packages/esp32/tools/esp-rv32/2601/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\\Users\\fkunz\\AppData\\Local\\arduino\\sketches\\81AB690D5A3CFA6DE61768B8EB361C84\\sketch\\Wire_Test.ino.cpp.o: in function `TwoWire::begin()': C:\Users\fkunz\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.11\cores\esp32/Wire.h:90:(.text._Z5setupv+0x2): undefined reference to `Wire'
C:/Users/fkunz/AppData/Local/Arduino15/packages/esp32/tools/esp-rv32/2601/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\\Users\\fkunz\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\3.3.11\\cores\\esp32/Wire.h:90:(.text.\_Z5setupv+0xa): undefined reference to `Wire' C:/Users/fkunz/AppData/Local/Arduino15/packages/esp32/tools/esp-rv32/2601/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\fkunz\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.11\cores\esp32/Wire.h:90:(.text._Z5setupv+0xe): undefined reference to `TwoWire::begin(int, int, unsigned long)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
Any help will be greatly appreciated.
#include <Wire.h>
void setup() {
Wire.begin();
}
void loop() {
}
Welcome to the forum
Exactly which ESP32 board are you using and which board have you got selected in the IDE ?
Your sample code from the opening post compiles fine on my system for both an ESP32 Dev Module and an ESP32C5 Dev Module.
I would start doing a clean compile; keep the <Shift> key pressed while starting the verify / compile.
If that does not help, enable verbose output during compilation under file → preferences, compile and post the output here.
Use a small sketch because the output can be long. You should find a line like
"C:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp-x32\\2601/bin/xtensa-esp32-elf-g++" -MMD -c "@C:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp32-libs\\3.3.11/flags/cpp_flags" -Wall -Wextra -Os -Werror=return-type -DF_CPU=240000000L -DARDUINO=10607 -DARDUINO_ESP32_DEV -DARDUINO_ARCH_ESP32 "-DARDUINO_BOARD=\"ESP32_DEV\"" "-DARDUINO_VARIANT=\"esp32\"" -DARDUINO_PARTITION_default "-DARDUINO_HOST_OS=\"windows\"" "-DARDUINO_FQBN=\"esp32:esp32:esp32:UploadSpeed=921600,CPUFreq=240,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=none,PSRAM=disabled,LoopCore=1,EventsCore=1,EraseFlash=none,JTAGAdapter=default,ZigbeeMode=default\"" -DESP32=ESP32 -DCORE_DEBUG_LEVEL=0 -DARDUINO_RUNNING_CORE=1 -DARDUINO_EVENT_RUNNING_CORE=1 -DARDUINO_USB_CDC_ON_BOOT=0 "@C:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp32-libs\\3.3.11/flags/defines" "-IC:\\Users\\bugge\\AppData\\Local\\Temp\\.arduinoIDE-unsaved2026812-11896-ujzqrd.1j47\\sketch_sep12a" -iprefix "C:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp32-libs\\3.3.11/include/" "@C:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp32-libs\\3.3.11/flags/includes" "-IC:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp32-libs\\3.3.11/qio_qspi/include" "-IC:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\3.3.11\\cores\\esp32" "-IC:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\3.3.11\\variants\\esp32" "-IC:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\3.3.11\\libraries\\Wire\\src" "@C:\\Users\\bugge\\AppData\\Local\\arduino\\sketches\\F53BB9727ED0A6AB6D12008223D8C1C8/build_opt.h" "@C:\\Users\\bugge\\AppData\\Local\\arduino\\sketches\\F53BB9727ED0A6AB6D12008223D8C1C8/file_opts" "C:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\3.3.11\\libraries\\Wire\\src\\Wire.cpp" -o "C:\\Users\\bugge\\AppData\\Local\\arduino\\sketches\\F53BB9727ED0A6AB6D12008223D8C1C8\\libraries\\Wire\\Wire.cpp.o"
Important in that line is the reference to Wire.cpp; if that is not there you have a corrupt installation of the ESP32 board package and I would suggest that you re-install the board package.
Below what I did select (first few lines of the verbose output)
FQBN: esp32:esp32:esp32
Using board 'esp32' from platform in folder: C:\Users\bugge\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.11
Using core 'esp32' from platform in folder: C:\Users\bugge\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.11
I was able to compile your code successfully on an ESP32C3 (Makergo clone) and an ESP32C6 (DFRobot Beetle)
Using library Wire at version 3.3.11 in folder: C:\Users\myself\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.11\libraries\Wire
"C:\\Users\\myself\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp-rv32\\2601/bin/riscv32-esp-elf-size" -A "C:\\Users\\myself\\AppData\\Local\\arduino\\sketches\\F1D2CB17B261A4C90B44813B95032D55/sketch_sep12a.ino.elf"
Sketch uses 299880 bytes (22%) of program storage space. Maximum is 1310720 bytes.
Global variables use 14064 bytes (4%) of dynamic memory, leaving 313616 bytes for local variables. Maximum is 327680 bytes.
Thanks for the information. I reinstalled Arduine but it made now difference. I'll work on it when it I have time as I expect it will take a while. For now, I found the ESP32_SoftWire library that works fine.
The ESP32 package must be the part that would need re-installation. (or possibly a roll-back to a previous version)
I was using esp32 package 3.3.11. I installed 3.3.10 and there are no compiler errors. your suggestion saved me a lot of time. Web searches were no help.
As others have said, your code compiles fine with 3.3.11. No roll back to 3.3.10 should have been needed.
I don't think you have found the root cause of your issue.
I suspect it was an error in the install of the ESP32 package 3.1.11, but that core version 3.1.10 is now correctly installed. It is very possible that an 'update' to version 3.1.11 now , after the rollback, does not result in compile errors. That requires testing by @fkunzler .
Uninstall a core, re-install a(nother) core, it is a very basic way of trying to solve an issue
I think i have 2 solutions 1 reInstall esp32 libirary and use the newest one and the second one is instead of the classical ide use vs-code with platformio installed on it once u get a hang u will love vs-code