i2c build issue in using multiple files

bmartin0
Posts: 33
Joined: Tue Aug 03, 2021 10:38 pm

i2c build issue in using multiple files

Postby bmartin0 » Thu Sep 23, 2021 7:21 pm

Hello,
I have an eclipse project based off of the i2c_test example in idf 4.3. I have added two components, init.c and h, and MCP23008.c and h.
I have init code in init.c and the prototype in init.h. I call these init functions in main.c where I have included the init.h file.
In MCP23008.c I have the routine i2c_master_init() defined and prototyped in MCP23008.h. I've included MCP23008.h in main.c where I
am calling i2c_master_init(). When I build I get 3 errors that say "undefined reference to `i2c_master_init'". It seems to be
working in the init components but for some reason I can't get it to recognize the MCP23008.h file included in main.
Any suggestions would be very much appreciated. main, init, and MCP23008 .c and .h files are attached.

I zipped up the 5 files as I was not able to post more than 3. The console output is shown below.

Thank you

Building in: C:\Workspace\Eclipse\datalogger100\build
cmake --build . -- -v
[1/5] cmd.exe /C "cd /D C:\Workspace\Eclipse\datalogger100\build\bootloader && C:\Users\barry\.espressif\tools\cmake\3.16.4\bin\cmake.exe --build ."
ninja: no work to do.
[2/3] cmd.exe /C "cd . && C:\Users\barry\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\app-template.elf.rsp -o app-template.elf && cd ."
FAILED: app-template.elf
cmd.exe /C "cd . && C:\Users\barry\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\app-template.elf.rsp -o app-template.elf && cd ."
c:/users/barry/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.c.obj):(.literal.app_main+0xc): undefined reference to `i2c_master_init'
c:/users/barry/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.c.obj): in function `app_main':
C:\Workspace\Eclipse\datalogger100\build/../main/main.c:22: undefined reference to `i2c_master_init'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Build complete (3 errors, 0 warnings): C:\Workspace\Eclipse\datalogger100\build
Total time taken to build the project: 937 ms

bmartin0
Posts: 33
Joined: Tue Aug 03, 2021 10:38 pm

Re: i2c build issue in using multiple files

Postby bmartin0 » Thu Sep 23, 2021 7:22 pm

The zip file did not get attached to the original post. Thanks
Attachments
i2c.zip
(3 KiB) Downloaded 252 times

bmartin0
Posts: 33
Joined: Tue Aug 03, 2021 10:38 pm

Re: i2c build issue in using multiple files

Postby bmartin0 » Thu Sep 23, 2021 7:48 pm

Hello,
I removed the static declaration and it builds fine. Not sure why but didn't want anyone to waste time on an issue that I've solved. In MCP23008.c and h, just remove the declaration "static" and it should build fine.
Thanks

Who is online

Users browsing this forum: Bing [Bot], DrMickeyLauer, ESP_rrtandler, Google [Bot] and 126 guests