arm gcc newlib retargetable locking fails because of command line order

Link step fails with multiple definition error because cmake has created a link command of the form
<CMAKE_C_COMPILER> $FLAGS $LINK_FLAGS @RSP_FILE -o $TARGET_FILE.

The $LINK_FLAGS contain -lc -lm. The problem is that this causes the dummy retargetable locks from newlib to be selected and then the objects list (RSP_FILE) causing multiple definitions.

I need the command to be of the form
<CMAKE_C_COMPILER> $FLAGS @RSP_FILE $LINK_FLAGS .-o $TARGET_FILE

I used message(STATUS “CMAKE_C_LINK_EXECUTABLE ${CMAKE_C_LINK_EXECUTABLE}”) to show the contents and the result was
CMAKE_C_LINK_EXECUTABLE <CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> -o <LINK_LIBRARIES>

This is obviously being overridden during the generation process

To answer my own problem
I added
set(CMAKE_C_LINK_EXECUTABLE
“<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> OBJECTS <LINK_FLAGS> -o <LINK_LIBRARIES>”)
BEFORE the project statement

p.s. OBJECTS should be in <> but must be some kind of formatting going on

Consider using target_link_libraries(myexe PRIVATE -lc -lm).
Then CMake handles them as libraries like any other, and not just as some non-library linker flag.

P.S. use preformatted text or a code block for posting code fragments. Either via editor symbols or markdown syntax.