cancel
Showing results for 
Search instead for 
Did you mean: 

Can't use RTT with CMake project

Hyderman
Associate II

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.

7 REPLIES 7
Semer CHERNI
ST Employee

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.

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.

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

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.

 

Andrew Neil
Evangelist III

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

https://forum.segger.com/

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.

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 ...