Can't use RTT with CMake project
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-25 7:09 PM
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.
- Labels:
-
STM32CubeMX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-28 3:22 AM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-28 7:05 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-02 5:38 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-02 5:58 AM
Hello@Ghofrane GSOURI,
I already tried to remove the syscall.c and in addition the syscall file doesn't define _write_r. If you look at my first message, it's newlib which define _write_r.
If I use my own cmake file, I don't have this problem. It is the way cubemx choses to link to libc which causes this problem but idk why.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-02 6:04 AM
RTT is a proprietary Segger thing - have you tried asking them?
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-02 8:31 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-02 8:55 AM
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 designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-07 5:51 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-07 6:18 AM
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 designed from scratch never works and cannot be patched up to make it work.
