2024-03-25 07: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.
2024-03-28 03:22 AM
Hello @Hyderman
First let me thank you for posting.
Could you share more details about the issue:
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.
2024-03-28 07: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.
2024-04-02 05: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
2024-04-02 05: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.
2024-04-02 06:04 AM
RTT is a proprietary Segger thing - have you tried asking them?
2024-04-02 08: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.
2024-04-02 08: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 ...