SOLVED: Undefined Reference to function (STM32 CubeIDE)

An undefined reference to function error in STM32 IDEs comes up when there is a problem with the linker configuration. If header files are included and a certain function is used with no link to the actual source for that function, you will get the “undefined reference” to function error.

Cause of "Undefined Reference to Function" Error

There can be two causes of undefined reference:

  • Missing C source file
    A source file may be present in the project directory in a folder. It may even be present in the workspace explorer, but the linker needs to be instructed to link the object files generated from the C source files.
    More on how to do this in the following section.
  • Missing library file
    A library file (usually a .a file) contains pre compiled source code in the form of a linkable library. You need a header file and a library file, both present in your workspace and the library file must be known to the linker.
Advertisement (third-party):

Solution to "Undefined Reference to Function" Error

The solution is to make sure the linker knows of and can access the contents of the entire source tree. How this can be done varies across IDEs and toolchains.

For the STM32 CubeIDE based on Eclipse, here is what you can do to ensure that all source files and libraries are included in your build.

Make sure you do a “full clean” and then build the whole project after changing the source tree.

For Cube IDE:

  • Open Project > Properties > C/C++ General > Paths and Symbols
  • Make sure your active debug/run configuration is selected.
  • Under the Source Location tab, Add Folder to make sure all folders that have sources are included in the list of source locations.
  • Under the Library Paths tab, Add a library file if your project depends on one.
stm32 undefined reference to function error solution
Adding Source and Library Files to Solve "Undefined Reference to Function" Error in STM32 CubeIDE
Change Log
  • Initial Release: 19 September 2021

You may also like

Leave a Comment

1 × 3 =


Nadia Schreiber September 19, 2022 - 8:16 pm

Thank you so much! I spent so long looking for this solution and you explained it perfectly :)

Ashok Sanap February 10, 2023 - 5:17 am

Really Helpfull