How to fix "undefined reference" error?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to fix "undefined reference" error?

Jump to solution
9,793 Views
yuzu_robocon
Contributor II

Hello

I'm developing code for evkmimxrt1060 using the mcuxpressoide IDE.
I added unity (https://github.com/ ThrowTheSwitch/Unity) testcode in iled_blinky example.
When I build the attachment, I get this error ↓

01:46:47 **** Build of configuration Debug for project evkmimxrt1060_iled_blinky ****
make -r -j8 all
Building target: evkmimxrt1060_iled_blinky.axf
Invoking: MCU Linker
arm-none-eabi-gcc -nostdlib -Xlinker -Map="evkmimxrt1060_iled_blinky.map" -Xlinker --gc-sections -Xlinker -print-memory-usage -Xlinker --sort-section=alignment -Xlinker --cref -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -T evkmimxrt1060_iled_blinky_Debug.ld -o "evkmimxrt1060_iled_blinky.axf" ./xip/evkmimxrt1060_flexspi_nor_config.o ./xip/evkmimxrt1060_sdram_ini_dcd.o ./xip/fsl_flexspi_nor_boot.o ./utilities/fsl_assert.o ./utilities/fsl_debug_console.o ./utilities/fsl_str.o ./unity/unity.o ./unity/unity_fixture.o ./startup/startup_mimxrt1062.o ./source/led_blinky.o ./source/semihost_hardfault.o ./drivers/fsl_clock.o ./drivers/fsl_common.o ./drivers/fsl_gpio.o ./drivers/fsl_lpuart.o ./device/system_MIMXRT1062.o ./component/uart/lpuart_adapter.o ./component/serial_manager/serial_manager.o ./component/serial_manager/serial_port_uart.o ./component/lists/generic_list.o ./board/board.o ./board/clock_config.o ./board/pin_mux.o
Memory region Used Size Region Size %age Used
BOARD_FLASH: 25332 B 8 MB 0.30%
/usr/local/mcuxpressoide-11.1.1_3241/ide/plugins/com.nxp.mcuxpresso.tools.linux_11.1.0.202001081728/tools/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: ./source/led_blinky.o: in function `main':
SRAM_DTC: 8624 B 128 KB 6.58%
SRAM_ITC: 0 GB 128 KB 0.00%
SRAM_OC: 0 GB 768 KB 0.00%
BOARD_SDRAM: 0 GB 30 MB 0.00%
NCACHE_REGION: 0 GB 2 MB 0.00%
/home/(user name)/Documents/MCUXpresso_11.1.1_3241/workspace/evkmimxrt1060_iled_blinky/Debug/../source/led_blinky.c:81: undefined reference to `RunAllTests'
makefile:40: recipe for target 'evkmimxrt1060_iled_blinky.axf' failed
collect2: error: ld returned 1 exit status
make: *** [evkmimxrt1060_iled_blinky.axf] Error 1
"make -r -j8 all" terminated with exit code 2. Build might be incomplete.

01:46:48 Build Failed. 4 errors, 0 warnings. (took 787ms)

If you have any hints that might help resolve this error, please let me know.

Thank you,
mari

1 Solution
9,738 Views
ErichStyger
Senior Contributor V

Your problem is that the linker does not find RunAllTests:

/home/(user name)/Documents/MCUXpresso_11.1.1_3241/workspace/evkmimxrt1060_iled_blinky/Debug/../source/led_blinky.c:81: undefined reference to `RunAllTests'

And the root cause is that your folders are not included in the build. The need to have this small blue 'C' on it:

pastedImage_1.png

By default, if you add folders in the latest versions of Eclipse they are not automatically added to the build: you need to uncheck that 'exclude from build' setting, see Exclude Source Files from Build in Eclipse | MCU on Eclipse 

I hope this helps,

Erich

View solution in original post

6 Replies
9,739 Views
ErichStyger
Senior Contributor V

Your problem is that the linker does not find RunAllTests:

/home/(user name)/Documents/MCUXpresso_11.1.1_3241/workspace/evkmimxrt1060_iled_blinky/Debug/../source/led_blinky.c:81: undefined reference to `RunAllTests'

And the root cause is that your folders are not included in the build. The need to have this small blue 'C' on it:

pastedImage_1.png

By default, if you add folders in the latest versions of Eclipse they are not automatically added to the build: you need to uncheck that 'exclude from build' setting, see Exclude Source Files from Build in Eclipse | MCU on Eclipse 

I hope this helps,

Erich

9,524 Views
superaga
Contributor III

Hi Erich,

I have the same issue (undefined reference), but it appears to be slightly different...

I created a new project following an example from NXP. I made it from scratch with the help of the Configuration Tool.

All looks apparently good, since all folders have the blue C icon... but when I built the project it fails (see picture).

It is weird (to me) because if I select Open Declaration from the context menu on the statement that triggers the error, I can open that file, but the linker doesn't find it... (see attached Console output).

superaga_0-1612158896958.png

One more question: If the editor can find the referenced/pointed files doesn't mean that this is on the path isn't it?

I tried to explore also the project properties, but also here looks fine:

superaga_1-1612159327590.png

Can you help me to understand this?

Many thanks!

Kind regards,

AGA

 

0 Kudos
9,520 Views
ErichStyger
Senior Contributor V

Pay attention to the 'implicit parameter declaration' warning (this is actually more of a programming error, and I consider this as an error not a warning).

The issue is that you have missed to include "fsl_gpio.h" in MKF64F_project.c. That symbol is defined as inline function in that header file, and if you use that symbol without including it, it is not available and the linker rightfully complains.

PS: always check and fix warnings. I always try to keep my code warning free.

9,516 Views
superaga
Contributor III

Hi Erich,

thanks for your help. That solved my error!

Since I generated the code using the Config Tool I though that all the drivers would have been added to main as well... This is a bit misleading... (drivers added to the project, but not included in the compilation..)

But in the end makes sense... The code is available, but not included until the user really needs it

It is my fault, since that error was triggered by the code I added.

 

superaga_0-1612162903138.png

And of course I'm completely agree about fixing all the warnings!

Kind regards,

AGA

9,496 Views
ErichStyger
Senior Contributor V
9,738 Views
yuzu_robocon
Contributor II

Thank you, the problem has been successfully resolved.
I can start learning this board! :smileyhappy:!!