Need Help Configuring CLion for STM32 Development on macOS

已回答

Hi everyone,

I’m new to STM32 development and need some assistance in configuring CLion to work with STM32 microcontrollers.
Here’s my current setup:
STM32CubeMX: Version 6.13.0 (latest at the time of writing)
STM32CubeCLT: Version 1.17.0 (installed specifically to use the ARM toolchains it provides)
CLion: Version 2024.3.1.1 (latest at the time of writing)
macOS: Sequoia (on MacBook Pro M3), Version 15.2 (latest at the time of writing)

Problem 1: STM32CubeMX Error
When I try to create a new project in CLion using STM32CubeMX (New Project -> STM32CubeMX) and click Create, I encounter the following error:
The Eclipse executable launcher was unable to locate its companion shared library.

I’ve ensured that all my tools are installed and up to date, but I don’t understand what might be causing this issue or how I can resolve it. Any help would be appreciated!

Problem 2: ARM Toolchain Configuration and Build Failure
I specifically installed STM32CubeCLT to use the ARM toolchains provided by STMicroelectronics. I configured the following build settings in CLion:
CMake: /opt/ST/STM32CubeCLT_1.17.0/CMake/bin/cmake (Version 3.28.1)
Build Tool: /opt/ST/STM32CubeCLT_1.17.0/Ninja/bin/ninja
C Compiler: /opt/ST/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc
C++ Compiler: /opt/ST/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-g++
Debugger: /opt/ST/STM32CubeCLT_1.17.0/STLink-gdb-server/bin/ST-LINK_gdbserver

Unfortunately, in the CLion toolchain settings, I receive the following errors:
C++ Compiler Test: Displays a warning: “Test CMake run finished with errors.”
 


I receive the following error trace:

-- The C compiler identification is GNU 12.3.1
-- The CXX compiler identification is GNU 12.3.1
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - no
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/ST/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc
-- Check for working C compiler: /opt/ST/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc - broken
CMake Error at /opt/ST/STM32CubeCLT_1.17.0/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/opt/ST/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/private/var/folders/qk/kpk9_nkj34987dyl3hj74l2w0000gn/T/cmake_check_environment/_build13433262515835532785/CMakeFiles/CMakeScratch/TryCompile-ICGS0P'
    
    Run Build Command(s): /opt/ST/STM32CubeCLT_1.17.0/Ninja/bin/ninja -v cmTC_20766
    [1/2] /opt/ST/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc   -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -fdiagnostics-color=always -o CMakeFiles/cmTC_20766.dir/testCCompiler.c.o -c /private/var/folders/qk/kpk9_nkj34987dyl3hj74l2w0000gn/T/cmake_check_environment/_build13433262515835532785/CMakeFiles/CMakeScratch/TryCompile-ICGS0P/testCCompiler.c
    FAILED: CMakeFiles/cmTC_20766.dir/testCCompiler.c.o 
    /opt/ST/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc   -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -fdiagnostics-color=always -o CMakeFiles/cmTC_20766.dir/testCCompiler.c.o -c /private/var/folders/qk/kpk9_nkj34987dyl3hj74l2w0000gn/T/cmake_check_environment/_build13433262515835532785/CMakeFiles/CMakeScratch/TryCompile-ICGS0P/testCCompiler.c
    arm-none-eabi-gcc: error: unrecognized command-line option '-arch'; did you mean '-march='?
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!

Error code: 1

Could anyone help me properly configure the ARM toolchain or guide me on how to resolve this error? Any advice or suggestions would be greatly appreciated!

 

Thank you in advance!

0

Hi Oleg!

Sorry for the delay in response.

  1. The Eclipse executable launcher was unable to locate its companion shared library. - This might be https://community.st.com/t5/stm32cubemx-mcus/stm32-cubemx-generate-code-fails-on-a-mac/td-p/749057. This comment https://community.st.com/t5/stm32cubemx-mcus/stm32-cubemx-generate-code-fails-on-a-mac/td-p/749057 mentions that the issue should be fixed. 
  2. ARM Toolchain Configuration and Build Failure: Please install the Arm GNU Toolchain from https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads.
-1

Hi Anna
I have the same problem. The cross compiler does not recognize the '-arch' parameter. I also get an error message saying that the '-arch' parameter cannot be found when using the following command.

Is there any other solution to fix it?

**ARM Toolchain Configuration and Build Failure: Please install the Arm GNU Toolchain from https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads.

0

Wltmlx, what compiler do you use? How did you install it?

0

Hi experts,

I think this issue is easy to reproduce. 

1. Use CubeMX generating a project, use CMake as the export format

2. Import the project to Clion

3. Config the CubeCTL as the toolchain on Clion and compile it

The root cause is that Clion or cmake use some default settings under M-chip. For example, if you don't configure the CMAKE_OSX_ARCHITECURES option, it will use arm64 as the -arch option to compile the code.

The following is my configuration screenshot and sorry for the Chinese chars, but it can show what I said.

The original writer's log shows the problem clearly.

1. -arch arm64

2. -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk

    /opt/ST/STM32CubeCLT_1.17.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc   -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -fdiagnostics-color=always -o CMakeFiles/cmTC_20766.dir/testCCompiler.c.o -c /private/var/folders/qk/kpk9_nkj34987dyl3hj74l2w0000gn/T/cmake_check_environment/_build13433262515835532785/CMakeFiles/CMakeScratch/TryCompile-ICGS0P/testCCompiler.c

Below is my issue. I tried to change some configuration but not work

/opt/ST/STM32CubeCLT_1.18.0/CMake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/opt/ST/STM32CubeCLT_1.18.0/Ninja/bin/ninja -DCMAKE_C_COMPILER=/opt/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc -DCMAKE_INSTALL_PREFIX:PATH=/opt/ST/STM32CubeCLT_1.18.0/Cmake -DCMAKE_OSX_ARCHITECTURES:STRING=cortex-m3 -DCMAKE_OSX_SYSROOT:PATH=/opt/ST/STM32CubeCLT_1.18.0/Cmake -G Ninja -S /Users/xxxxx/Documents/CubeMX/si47xx -B /Users/xxxxx/Documents/CubeMX/si47xx/cmake-build-debug-stm32
-- The C compiler identification is GNU 13.3.1
-- The CXX compiler identification is GNU 13.3.1
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - no
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc
-- Check for working C compiler: /opt/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc - broken
CMake Error at /opt/ST/STM32CubeCLT_1.18.0/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/opt/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/Users/xxxxx/Documents/CubeMX/si47xx/cmake-build-debug-stm32/CMakeFiles/CMakeScratch/TryCompile-GQOJM5'
    
    Run Build Command(s): /opt/ST/STM32CubeCLT_1.18.0/Ninja/bin/ninja -v cmTC_768a7
    [1/2] /opt/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc   -std=gnu11 -arch cortex-m3 -isysroot /opt/ST/STM32CubeCLT_1.18.0/Cmake -fdiagnostics-color=always -o CMakeFiles/cmTC_768a7.dir/testCCompiler.c.o -c /Users/xxxxx/Documents/CubeMX/si47xx/cmake-build-debug-stm32/CMakeFiles/CMakeScratch/TryCompile-GQOJM5/testCCompiler.c
    FAILED: CMakeFiles/cmTC_768a7.dir/testCCompiler.c.o 
    /opt/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc   -std=gnu11 -arch cortex-m3 -isysroot /opt/ST/STM32CubeCLT_1.18.0/Cmake -fdiagnostics-color=always -o CMakeFiles/cmTC_768a7.dir/testCCompiler.c.o -c /Users/xxxxx/Documents/CubeMX/si47xx/cmake-build-debug-stm32/CMakeFiles/CMakeScratch/TryCompile-GQOJM5/testCCompiler.c
    arm-none-eabi-gcc: error: unrecognized command-line option '-arch'; did you mean '-march='?
    ninja: build stopped: subcommand failed.
0

I have found a way to bypass this issue.

Add the below block into your CMakeLists.txt of the project, after the line “cmake_minimum_required(VERSION 3.22)”. After adding the following code, please also remove the cache folder “{ProjectRootFolder}/cmake-build-debug-stm32”.

# Setup compiler settings
if(NOT CMAKE_TOOLCHAIN_FILE AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
    set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/gcc-arm-none-eabi.cmake")
endif()
# CROSS-COMPILATION FIX FOR macOS - Prevent Apple-specific flags
if(APPLE OR CMAKE_HOST_APPLE)
    # Completely disable Apple-specific behavior for cross-compilation
    set(CMAKE_OSX_SYSROOT "" CACHE STRING "" FORCE)
    set(CMAKE_OSX_ARCHITECTURES "" CACHE STRING "" FORCE)
    set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "" FORCE)

    # Override system detection
    set(CMAKE_SYSTEM_NAME Generic CACHE STRING "" FORCE)
    set(CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "" FORCE)

    # Prevent CMake from using Apple's framework search paths
    set(CMAKE_FIND_FRAMEWORK NEVER)
    set(CMAKE_FIND_APPBUNDLE NEVER)

    # Force cross-compilation mode
    set(CMAKE_CROSSCOMPILING TRUE CACHE BOOL "" FORCE)
endif()
0

请先登录再写评论。