Skip to main content
Associate II
July 31, 2024
Solved

CMAKE build works only in IDE

  • July 31, 2024
  • 4 replies
  • 1740 views

Hello,
I have successfully created a new cmake project in IDE 1.16. Everything I need works - the project is successfully compiled, the BIN file is successfully run in the MCU:

[ 97%] Building C object CMakeFiles/KubergCMAKE.dir/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_uart_ex.c.obj

[100%] Linking C executable KubergCMAKE.elf

text data bss dec hex filename

48528 128 3376 52032 cb40 C:/Projekty/KubergCMAKE/Release/KubergCMAKE.elf

[100%] Built target KubergCMAKE

 

13:57:54 Build Finished. 0 errors, 0 warnings. (took 16s.631ms)

 

However, I am unable to compile the project from the command line window.
cmake --build Release

This command only succesfuly compile source files - 100% done, but when try to lining:
[100%] Linking C executable KubergCMAKE.elf

ends with this error:

.......
............
CMakeFiles/KubergCMAKE.dir/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_uart_ex.c.obj : No such file or directory
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/KubergCMAKE.dir/build.make:639: KubergCMAKE.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/KubergCMAKE.dir/all] Error 2

 

Has anyone solved the same problem?

Thank You, Jan.

    This topic has been closed for replies.
    Best answer by Souhaib MAZHOUD

    Hello @JKol 

    I suggest that you delete the Debug folder and rebuild the project with command line below:

    cmake -DCMAKE_TOOLCHAIN_FILE=cubeide-gcc.cmake  -S ./ -B Debug -GUnix -DCMAKE_BUILD_TYPE=Debug

    cmake --build Debug --clean-first

    It seems that the project was built using an older version of CubeIDE.

    KR,

    Souhaib

     

    4 replies

    ST Technical Moderator
    July 31, 2024

    Hello @JKol ,

    First let me thank you for posting!

    I am not able to reproduce your issue in my side, 

    Could you add your project for further investigation.

    Thx,

    Souhaib

    To give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
    JKolAuthor
    Associate II
    August 1, 2024

    Hello Souhaib,

    my project is based on empty project reated in IDE - STM32 CMake Project. Project is attached.

    Thank you.
    Jan.

    JKol_0-1722489682906.png

    JKol_1-1722489692651.png

     

    Souhaib MAZHOUDBest answer
    ST Technical Moderator
    August 1, 2024

    Hello @JKol 

    I suggest that you delete the Debug folder and rebuild the project with command line below:

    cmake -DCMAKE_TOOLCHAIN_FILE=cubeide-gcc.cmake  -S ./ -B Debug -GUnix -DCMAKE_BUILD_TYPE=Debug

    cmake --build Debug --clean-first

    It seems that the project was built using an older version of CubeIDE.

    KR,

    Souhaib

     

    To give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
    JKolAuthor
    Associate II
    August 1, 2024

    Hello Souhaib,

    thanks a lot it's working :-). I only
    1. added the path to compiler files to PATH variable:
    c:\ST\STM32CubeIDE_1.13.2\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.12.3.rel1.win32_1.0.200.202406191623\tools\bin
    2. changed cmake command:
    cmake -DCMAKE_TOOLCHAIN_FILE=cubeide-gcc.cmake -S ./ -B Debug -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug

    Best regards,
    Jan.