3 years, 1 month ago.

[Necleo-rtos-basic] Linking ERROR due to multiple definition of `software_init_hook' with mbed-cli


It's OK while compiling & linking by using online-compiler. But, When i used mbed-cli, I got linking ERROR as below. What's the problem ?

ewrcu@PC C:\Users\ewrcu\Mbed

[mbed] Importing program "Nucleo_rtos_basic" from "https://os.mbed.com/teams/ST/code/Nucleo_rtos_basic" at latest revision in the current branch [mbed] Adding library "mbed-rtos" from "https://mbed.org/users/mbed_official/code/mbed-rtos" at rev #bdd541595fc5 [mbed] Adding library "mbed" from "https://mbed.org/users/mbed_official/code/mbed/builds" at rev #86740a56073b [mbed] Downloading library build "86740a56073b" (might take a minute) [mbed] Unpacking library build "86740a56073b" in "C:\Users\ewrcu\Mbed\Nucleo_rtos_basic\mbed" [mbed] Couldn't find build tools in your program. Downloading the mbed 2.0 SDK tools...

ewrcu@PC C:\Users\ewrcu\Mbed

cd Nucleo_rtos_basic

ewrcu@PC C:\Users\ewrcu\Mbed\Nucleo_rtos_basic

mbed compile -t GCC_ARM -m NUCLEO_F103RB

Building project Nucleo_rtos_basic (NUCLEO_F103RB, GCC_ARM) Scan: . Scan: mbed Scan: env Compile [ 4.8%]: main.cpp Compile [ 9.5%]: RtosTimer.cpp Compile [ 14.3%]: Mutex.cpp Compile [ 19.0%]: Semaphore.cpp Compile [ 23.8%]: Thread.cpp Compile [ 28.6%]: HAL_CM3.S Compile [ 33.3%]: SVC_Table.S Compile [ 38.1%]: rtos_idle.c Compile [ 42.9%]: HAL_CM.c Compile [ 47.6%]: RTX_Conf_CM.c Compile [ 52.4%]: rt_Event.c Compile [ 57.1%]: rt_CMSIS.c Compile [ 61.9%]: rt_List.c Compile [ 66.7%]: rt_Mailbox.c Compile [ 71.4%]: rt_MemBox.c Compile [ 76.2%]: rt_Robin.c Compile [ 81.0%]: rt_Mutex.c Compile [ 85.7%]: rt_Semaphore.c Compile [ 90.5%]: rt_System.c Compile [ 95.2%]: rt_Time.c Compile [100.0%]: rt_Task.c Link: Nucleo_rtos_basic ./mbed/86740a56073b/TARGET_NUCLEO_F103RB/TOOLCHAIN_GCC_ARM/mbed_retarget.o: In function `software_init_hook': mbed_retarget.cpp:(.text.software_init_hook+0x0): multiple definition of `software_init_hook' ./BUILD/NUCLEO_F103RB/GCC_ARM/mbed-rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.o:RTX_Conf_CM.c:(.text.software_init_hook+0x0): first defined here collect2.exe: error: ld returned 1 exit status [ERROR] ./mbed/86740a56073b/TARGET_NUCLEO_F103RB/TOOLCHAIN_GCC_ARM/mbed_retarget.o: In function `software_init_hook': mbed_retarget.cpp:(.text.software_init_hook+0x0): multiple definition of `software_init_hook' ./BUILD/NUCLEO_F103RB/GCC_ARM/mbed-rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.o:RTX_Conf_CM.c:(.text.software_init_hook+0x0): first defined here collect2.exe: error: ld returned 1 exit status

[mbed] ERROR: "C:\Python27\python.exe" returned error code 1. [mbed] ERROR: Command "C:\Python27\python.exe -u C:\Users\ewrcu\Mbed\Nucleo_rtos_basic\.temp\tools\make.py -t GCC_ARM -m NUCLEO_F103RB source . build .\BUILD\NUCLEO_F103RB\GCC_ARM" in "C:\Users\ewrcu\Mbed\Nucleo_rtos_basic" -

ewrcu@PC C:\Users\ewrcu\Mbed\Nucleo_rtos_basic


Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F103RBT6 microcontroller.

2 Answers

3 years, 1 month ago.


The example program you are using hasn't been updated in over a year. Additionally, that repo is not maintained by Arm Mbed so I am not 100% confident that the example will work anymore.

I can suggest (and I just tried it myself) is to create a new blank program (empty folder)

Create a file called main.cpp and copy and paste the main.cpp contents from the example project you were referring to:

RTOS example

#include "mbed.h"
void print_char(char c = '*')
    printf("%c", c);

Thread thread;
DigitalOut led1(LED1);
void print_thread()
    while (true) {
int main()
    printf("\n\n*** RTOS basic example ***\n");
    while (true) {
        led1 = !led1;

Finally, add the mbed-os library to the project. Do this with the following command:

mbed add mbed-os

You should now be able to compile with the target tag: NUCLEO-F103RB:

mbed compile -t GCC_ARM -m nucleo_f103rb

Some things to note:

  • The old example you were looking at used mbed2 (non RTOS) version of mbed and added the RTOS functionality separately, which may have caused multiple definitions of some libraries
  • Mbed5 (known as mbed-os) has the RTOS functionality baked into it, therefore doesn't require additional libraries
  • The thread libraries have been changed since that repo was create. Please reference the new thread libraries. Note: I modified the code to use the new libraries
  • By following the above steps, you still are able to build and demonstrate a working RTOS on the NUCLEO-F103RB

3 years, 1 month ago.


I have updated this example by using mbed-os library and latest thread syntax.