undefined reference when linking .obj files in Visual Studio Code and ESP32 IDE

BivvyCoder
Posts: 3
Joined: Sun Jan 28, 2024 5:20 pm

undefined reference when linking .obj files in Visual Studio Code and ESP32 IDE

Postby BivvyCoder » Sun Jan 28, 2024 5:38 pm

I'm trying to break my project down into separate files to make it more manageable.
Working in Visual Studio Code using the ESP32 IDE.
The code works fine if I have everything in one file (app_main.c) but fails when I try to break it into more manageable components.

I've split out the GPIO configuration and functions into a separate file GPIO.c and also added a new file GPIO.h
  1. //GPIO.h
  2. static void configure_led(void);
  3. static void configure_ext_LEDs(void);
  4. static void configure_joystick(void);
These files are in the main directory along with main_app.c and CakeLists.txt

In the main_app.c I've added #include "GPIO.h"
and updated the CMakeLists.txt file so it includes GPIO.c
  1. idf_component_register(SRCS "app_main.c" "GPIO.c"
  2.                     INCLUDE_DIRS "." )
All the code compiles, I can find app_main.c.obj and GPIO.c.obj in the Build directory, but the process fails in the linker:

Code: Select all

[977/979] Linking CXX executable wifi_prov_mgr.elf
FAILED: wifi_prov_mgr.elf
cmd.exe /C "cd . && C:\Users\chris\.espressif\tools\riscv32-esp-elf\esp-12.2.0_20230208\riscv32-esp-elf\bin\riscv32-esp-elf-g++.exe -march=rv32imc_zicsr_zifencei -nostartfiles -march=rv32imc_zicsr_zifencei --specs=nosys.specs    -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32C3=0 -Wl,--Map=C:/Users/chris/Programming/esp-idf-5.1.2/examples/provisioning/wifi_prov_mgr/build/wifi_prov_mgr.map -Wl,--no-warn-rwx-segments -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--warn-common -T esp32c3.peripherals.ld -T esp32c3.rom.ld -T esp32c3.rom.api.ld -T esp32c3.rom.libgcc.ld -T esp32c3.rom.newlib.ld -T esp32c3.rom.version.ld -T esp32c3.rom.eco3.ld -T memory.ld -T sections.ld @CMakeFiles\wifi_prov_mgr.elf.rsp -o wifi_prov_mgr.elf  && cd ."
c:/users/chris/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/12.2.0/../../../../riscv32-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(app_main.c.obj): in function `app_main':
C:/Users/chris/Programming/esp-idf-5.1.2/examples/provisioning/wifi_prov_mgr/main/app_main.c:289: undefined reference to `configure_led'
c:/users/chris/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/12.2.0/../../../../riscv32-esp-elf/bin/ld.exe: C:/Users/chris/Programming/esp-idf-5.1.2/examples/provisioning/wifi_prov_mgr/main/app_main.c:299: undefined reference to `configure_ext_LEDs'
c:/users/chris/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/12.2.0/../../../../riscv32-esp-elf/bin/ld.exe: C:/Users/chris/Programming/esp-idf-5.1.2/examples/provisioning/wifi_prov_mgr/main/app_main.c:300: undefined reference to `configure_joystick'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
I've searched for hours to try to find a fix but have drawn a blank.

Any help very gratefully received.

boarchuz
Posts: 575
Joined: Tue Aug 21, 2018 5:28 am

Re: undefined reference when linking .obj files in Visual Studio Code and ESP32 IDE

Postby boarchuz » Mon Jan 29, 2024 5:17 am

Remove 'static'

BivvyCoder
Posts: 3
Joined: Sun Jan 28, 2024 5:20 pm

Re: undefined reference when linking .obj files in Visual Studio Code and ESP32 IDE

Postby BivvyCoder » Mon Jan 29, 2024 8:44 am

Thanks @boarchuz. That fixed it.
What's the correct emoji for embarrassed rookie? :oops:

Who is online

Users browsing this forum: No registered users and 96 guests