Skip to main content
Associate
March 26, 2024
Question

Can't use RTT with CMake project

  • March 26, 2024
  • 3 replies
  • 3753 views

I tried to use cmake with CubeMx but I cant make RTT works.

Error:

multiple definition of `_write_r'; /usr/lib/gcc/arm-none-eabi/13.2.0/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o):/build/arm-none-eabi-newlib/src/build-nano/arm-none-eabi/thumb/v7-m/nofp/newlib/../../../../../../newlib-4.3.0.20230120/newlib/libc/reent/writer.c:45: first defined here

RTT needs to define _write_r but seems already define.

If I comment this line from the gcc tool chain it solves the problem:

set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lc -lm -Wl,--end-group")

Before I used my custom cmake this way:
```

target_link_options(${EXECUTABLE} PRIVATE
-T${MCU_LINKER_SCRIPT}
${CPU_PARAMETERS}
-Wl,-Map=${CMAKE_PROJECT_NAME}.map
--specs=nosys.specs
-Wl,--start-group
-lc
-lm
-lstdc++
-Wl,--end-group
-Wl,--print-memory-usage)

```

and have no problem so I don't really understand why.

Also tried -fcommon it does nothing.

3 replies

Semer CHERNI
ST Employee
March 28, 2024

Hello @Hyderman 

First let me thank you for posting.

Could you share more details about the issue:

  • ioc file
  • steps done to generate and build the project
  • with which environment the build was made

I made a test by generating a CMake project with CubeMX and build it with VSCode and I have a successful build.

KR,
Semer.

HydermanAuthor
Associate
March 28, 2024

For example with stm32f103c8t6:

Project manager:

- Copy only necessary files

- Generate peripheral initialization as pair

Toolchain to CMake

Generate code

Adding RTT to CMakeLists.txt:

file(GLOB_RECURSE RTT CONFIGURE_DEPENDS
 ${CMAKE_CURRENT_SOURCE_DIR}/RTT/*c
 ${CMAKE_CURRENT_SOURCE_DIR}/RTT/*S)
add_executable(${CMAKE_PROJECT_NAME}
 ${RTT})

Add necessary files for RTT (see screenshot)

I use a Makefile to call CMake commands but the command to configure is this one:

cmake -GNinja -Bbuild -DPROJECT_NAME=test-cmake -DCMAKE_BUILD_TYPE=Debug

cmake --build build

I am on Linux.

The redefinition of _write_r in the "SEGGER_RTT_Syscalls_GCC.c " file from RTT.

Ghofrane GSOURI
Technical Moderator
April 2, 2024

Hello @Hyderman 

By seeing the the attached screenshot ,the RTT library is adding GCC syscalls while MX also generate them in a file syscall.c (same for CubeIDE and Makefile) which causes double definition issue.

I believe you need to keep only one syscall to fix the issue.

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Andrew Neil
Super User
April 2, 2024

RTT is a proprietary Segger thing - have you tried asking them?

https://forum.segger.com/

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
HydermanAuthor
Associate
April 2, 2024

The problem don't come frome Segger RTT files, it comes from the cmake from cubemx define _write_r while it shouldn't.

RTT needs to define _write_r but newlib define it while it shouldn't.

In itself, it's not a bug. Just wanted the signal that the cmake from cubemx don't work with RTT.

Andrew Neil
Super User
April 2, 2024

Sure, but Segger must know about this - the duplicates are coming from standard GCC/ARM libraries with standard GCC/ARM tools.

Segger do like to claim that the work closely with the likes of ST ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate II
April 7, 2025

Any update on this ?
Having similar issue, but redefinition happens in libc_nano
SEGGER_RTT_Syscalls_GCC.c:117: multiple definition of `_write_r'; C:/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(libc_a-writer.o):(.text._write_r+0x0): first defined here

 

Andrew Neil
Super User
April 7, 2025

Seems like the previous answers have it all covered:


@serg22 wrote:

redefinition happens in libc_nano
SEGGER_RTT_Syscalls_GCC.c:


So don't add that file to your Project!

Or remove the syscalls created by CubeMX.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.