Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


Problem with "undefined reference to" [SOLVED]

Hello,

I know that this question has been posted many times, but none of the proposed solutions have worked.

The problem I have should be easy to fix, bu I cannot find the way to do it. I have tried many ways to do the same thing, but all of them lead to the same problem, which is:

I:/Ac6/SystemWorkbench/workspace/nz32-sc151-fir_example/Src/main.cpp:174: undefined reference to `arm_snr_f32(float*, float*, unsigned long)’
collect2.exe: error: ld returned 1 exit status

The function arm_snr_f32 is defined in math_helper.h and implemented in math_helper.c. Files can be found on: https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/DSP/Examples/ARM/arm_fir_exampleQuestion

The files are in a folder called Inc in my project’s workspace. Then, in the project explorer, I linked this folder and its files. I have also added the folder in Project properties > C/C++ General > Path and Symbols: “${WorkspaceDirPath}/.../Inc”

When I build the project, I see in the Debug folder that the object file math_helper.o is being created. However, my main.cpp program complains again and again.

Other things I have tried are e.g., creating a header file with the definition of some function and another source file with the implementation, both in the same src folder where my main.cpp is located. It can find the header, but when it comes to building the project successfully, reference error.

I would very much appreciate any help here.

Many thanks

David

France

Hi David,

The problem here is that the math_helper.c file is a C program and your main.cpp is obviously a C++ program. You must slightly modify the math_helper.h file so that it declares its functions correctly to be called from C++: You should add, just after line 47 in math_helper.h:
#ifdef __cplusplus
extern "C" {
#endif
and just before the final #endif
#ifdef __cplusplus
}
#endif

so that your functions are properly declared as C functions when math_helper.h is included in main.cpp.

Hope this helps,

Bernard (Ac6)

Hello Bernard,

I just added the lines of code you indicated and all works fine now. Many thanks.

Though I have a lot of experience on embedded programming (only C), it is now when I am transitioning to C and C++ projects, and this is something I didn’t know of. It is always good to learn something new.

Thanks again,

Best
David


 

Newest Forum Posts

  1. Монтаж камина с грилем в Москве - установка и барбекю by KpddomErorb, 2025-05-10 18:28
  2. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  9. Build a project in "release" mode by tang, 2025-02-20 10:36
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35

Last-Modified Blogs