cancel
Showing results for 
Search instead for 
Did you mean: 

Debugging in STM32CubeIDE

MCrew.1
Associate III

Hello,

I am working on a project where I have created several of my own files (.h and .cpp) but I am having issues with undefined reference to certain functions. I cannot solve this issue while having the files separated, but I was wondering if it is possible to generate and view the files combined together in assembly code? The functions are accessible in the main.c file, but not in my own files.

Thanks,

MC

4 REPLIES 4
TDK
Guru

You need to put the function definitions in a header file and then #include that header in the source files you wish to use it in. This is a basic C concept.

main.h:
 
void my_function();
 
 
main.c:
 
#include "main.h"
 
void my_function() {
  // stuff...
}
 
 
 
other_source_file.c:
 
#include "main.h"
 
void other_function() {
  my_function();
}

If you feel a post has answered your question, please click "Accept as Solution".
MCrew.1
Associate III

I know this concept and I have done this already, however I am trying to debug the undefined reference error.

An "undefined reference error" suggests you haven't done this correctly.

If you feel a post has answered your question, please click "Accept as Solution".

You can check which files the linker is linking by using the "-Wl,--verbose" option (Project > Properties > C/C++ Build > Settings > Tool settings > MCU GCC Linker > General).

For analyzing individual .o files, you may use objdump with its many options. You find a copy under C:\ST\STM32CubeIDE\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.7-2018-q2-update.win32_1.4.0.202007081208\tools\bin. The path may vary depending on your install path and tool version.

hth

KnarfB