Solving linker error in MCUXpresso

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

Solving linker error in MCUXpresso

1,103 Views
drsmith_yorku
Contributor III

I'm trying to integrate the TinyUSB library within an MCUXpresso project but I'm running into an issue when when I try to call the tusb_init() function.   I get the following error, which appears to be associated with the linker:

Building target: MKL25Z4_Project_TinyUSB_v6.axf

Invoking: MCU Linker

arm-none-eabi-gcc -nostdlib -L"/Users/drsmith/Documents/MCUXpressoIDE_11.8.1_1197/workspace/MKL25Z4_Project_TinyUSB_v6/tinyusb/src" -Xlinker -Map="MKL25Z4_Project_TinyUSB_v6.map" -Xlinker --gc-sections -Xlinker -print-memory-usage -Xlinker --sort-section=alignment -Xlinker --cref -mcpu=cortex-m0plus -mthumb -T MKL25Z4_Project_TinyUSB_v6_Debug.ld -o "MKL25Z4_Project_TinyUSB_v6.axf" ./utilities/fsl_debug_console.o ./tinyusb/src/device/usbd.o ./tinyusb/src/device/usbd_control.o ./tinyusb/src/common/tusb_fifo.o ./tinyusb/src/class/video/video_device.o ./tinyusb/src/class/vendor/vendor_device.o ./tinyusb/src/class/vendor/vendor_host.o ./tinyusb/src/class/usbtmc/usbtmc_device.o ./tinyusb/src/class/net/ecm_rndis_device.o ./tinyusb/src/class/net/ncm_device.o ./tinyusb/src/class/msc/msc_device.o ./tinyusb/src/class/msc/msc_host.o ./tinyusb/src/class/midi/midi_device.o ./tinyusb/src/class/hid/hid_device.o ./tinyusb/src/class/hid/hid_host.o ./tinyusb/src/class/dfu/dfu_device.o ./tinyusb/src/class/dfu/dfu_rt_device.o ./tinyusb/src/class/cdc/cdc_device.o ./tinyusb/src/class/cdc/cdc_host.o ./tinyusb/src/class/cdc/cdc_rndis_host.o ./tinyusb/src/class/bth/bth_device.o ./tinyusb/src/class/audio/audio_device.o ./tinyusb/src/tusb.o ./startup/startup_mkl25z4.o ./source/MKL25Z4_Project_TinyUSB_v6.o ./source/mtb.o ./source/semihost_hardfault.o ./drivers/fsl_clock.o ./drivers/fsl_common.o ./drivers/fsl_flash.o ./drivers/fsl_gpio.o ./drivers/fsl_lpsci.o ./drivers/fsl_smc.o ./drivers/fsl_uart.o ./board/board.o ./board/clock_config.o ./board/peripherals.o ./board/pin_mux.o ./CMSIS/system_MKL25Z4.o

/Applications/MCUXpressoIDE_11.8.1_1197/ide/plugins/com.nxp.mcuxpresso.tools.macosx_11.8.1.202308071233/tools/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld: ./source/MKL25Z4_Project_TinyUSB_v6.o: in function `main':

/Users/drsmith/Documents/MCUXpressoIDE_11.8.1_1197/workspace/MKL25Z4_Project_TinyUSB_v6/Debug/../source/MKL25Z4_Project_TinyUSB_v6.c:43: undefined reference to `tusb_init'

I've placed all the .c and .h files for TinyUSB within its own folder inside the workspace.  And I've included the subfolders for the TinyUSB header and source files within Settings -> C/C++ General ->  Paths and Symbols

But I'm struggling to figure out how to ensure that the linker find functions like tusb_init().   What's the preferred way to define paths for the linker in MCUXpresso?

 

thanks!

 

James

0 Kudos
Reply
5 Replies

1,065 Views
drsmith_yorku
Contributor III

Vielen Dank, Erich!

The compiler is creating the tusb.o object file:

drsmith_yorku_0-1702403072497.png

And that object file comes from tusb.h and tusb.c (where tusb_init() is defined):

drsmith_yorku_1-1702403166003.png

I saw your post about exclusion earlier and made sure that the exclusion check box was not checked.

 

drsmith_yorku_2-1702403354639.png

and I looked at the alternative that you suggested and it seems to be on the default (assuming that means include in build)

drsmith_yorku_3-1702403524339.png

 

all the best,

James

 

 

0 Kudos
Reply

1,062 Views
ErichStyger
Specialist I

Hi James,

what about the folder properties where the file is in?

Maybe the folder is not included into the build?

Erich

0 Kudos
Reply

1,074 Views
ErichStyger
Specialist I

Hi James,

the linker error is about the fact that it does not find the function tusb_init(). Check your sources and find out where this function is located, and if the module for it (.o) is listed in the ones passed to the linker.

It could be that you have missed including/compiling that file or folder for it. Make sure the file or folder is not 'excluded from build', see https://mcuoneclipse.com/2014/07/22/exclude-source-files-from-build-in-eclipse/

I hope this helps,

Erich

0 Kudos
Reply

1,038 Views
drsmith_yorku
Contributor III

 Hi Erich,

still working on it... now putting all the files from TinyUSB into the main source folder... just to narrow down possible issues.  Now going to check linker folder lists...

0 Kudos
Reply

977 Views
drsmith_yorku
Contributor III

Aha. I believe that I've figured it out. It had nothing to do with MCUXpresso's settings. They were fine. What was going on is that the TinyUSB library uses preprocessor defines in a configuration file that are then interpreted to include (or not) the header file.  

Once I defined it properly, the linker was able to find the resulting object file.

 

James

 

Screen Shot 2023-12-18 at 9.27.03 PM.pngScreen Shot 2023-12-18 at 9.29.30 PM.png

0 Kudos
Reply