mbed-tools icon indicating copy to clipboard operation
mbed-tools copied to clipboard

Missing instructions on how to tell Cmake where to find your compiler

Open maclobdell opened this issue 3 years ago • 10 comments

Describe the bug

The instructions say to have a compiler installed, which I do (ARM GCC 9). I have also installed CMake and added to my path.

I’m on Mac OS X Big Sur.

Cmake is installed here: /Applications/CMake.app/Contents/bin

GCC for ARM is installed here: /Applications/ARM/bin

In the prior generation of Mbed tools I set my compiler path with mbed config -G GCC_ARM_PATH=/Applications/ARM/bin. However, I don't now how to do that in the new tools.

If I blindly follow the steps in the guide, I get the following error. It appears that Cmake hasn’t been told where the correct compiler is. It is trying to use the Apple version.

-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- The ASM compiler identification is Clang
-- Found assembler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - broken
-- Configuring incomplete, errors occurred!
See also "/Users/maclob01/Documents/mbed-tools-2/mbed-os-example-blinky/cmake_build/CMakeFiles/CMakeOutput.log".
See also "/Users/maclob01/Documents/mbed-tools-2/mbed-os-example-blinky/cmake_build/CMakeFiles/CMakeError.log".

To Reproduce Steps to reproduce the behavior:

  1. Follow the guide on a Mac without having anything previously setup https://os.mbed.com/docs/mbed-os/v6.8/build-tools/use.html

Expected behavior Clear information about how to configure cmake to use the right compiler.

Screenshots n/a

Desktop (please complete the following information):

  • OS: Mac
  • Version: 11.11

Mbed (please complete the following information):

  • Device: n/a
  • Mbed OS Version: n/a
  • Mbed CLI 2 Version: 7.4.0

Additional context n/a

maclobdell avatar Mar 22 '21 20:03 maclobdell

I would highly recommend you use homebrew (https://brew.sh) to install cmake and arm-gcc.

Are you on a intel or M1 Mac?

ladislas avatar Mar 22 '21 20:03 ladislas

You can use the following for arm-gcc: https://github.com/osx-cross/homebrew-arm

For cmake just brew install cmake will do.

ladislas avatar Mar 22 '21 20:03 ladislas

I assume this is related to https://github.com/ARMmbed/mbed-os/issues/14446 (regarding CMAKE_<LANG>_COMPILER set up. We hardcoded it and it should be fixed as CMake provides a way to configure it.

0xc0170 avatar Mar 23 '21 09:03 0xc0170

@maclobdell Is arm-none-eabi-gcc in your path? What's the result of running which arm-none-eabi-gcc?

Patater avatar Mar 23 '21 09:03 Patater

Thanks for the help. Here are my responses.

  • I have an Intel Mac. Recently upgraded to Big Sur.
  • The compiler wasn't part of my path. I tried adding it. Still no luck.
  • I cleaned up my brew installation (issue with Big Sur)
  • I reinstalled cmake and the compiler using brew
  • removed the cmake_build folder. started over...

unfortunately, I'm back to the same problem.

I tried passing in the compiler paths manually. But it seems to fail an environment verification step now.

maclob01@C02CL7CDLVDL mbed-os-example-blinky % cmake -S . -B cmake_build -GNinja -DCMAKE_BUILD_TYPE=debug -DCMAKE_C_COMPILER=/usr/local/bin/arm-none-eabi-gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/arm-none-eabi-g++ -DCMAKE_ASM_COMPILER=/usr/local/bin/arm-none-eabi-gcc

CMake Error at mbed-os/tools/cmake/app.cmake:10 (include):
  include could not find load file:

    /Users/maclob01/Documents/mbed-tools-2/mbed-os-example-blinky/cmake_build/mbed_config.cmake
Call Stack (most recent call first):
  CMakeLists.txt:10 (include)


CMake Error at mbed-os/tools/cmake/toolchain.cmake:103 (include):
  include could not find load file:

    /Users/maclob01/Documents/mbed-tools-2/mbed-os-example-blinky/mbed-os/tools/cmake/toolchains/.cmake
Call Stack (most recent call first):
  mbed-os/tools/cmake/app.cmake:15 (include)
  CMakeLists.txt:10 (include)


CMake Error at mbed-os/tools/cmake/toolchain.cmake:104 (include):
  include could not find load file:

    /Users/maclob01/Documents/mbed-tools-2/mbed-os-example-blinky/mbed-os/tools/cmake/cores/.cmake
Call Stack (most recent call first):
  mbed-os/tools/cmake/app.cmake:15 (include)
  CMakeLists.txt:10 (include)


-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- The ASM compiler identification is GNU
-- Found assembler: /usr/local/bin/arm-none-eabi-gcc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/bin/arm-none-eabi-gcc
-- Check for working C compiler: /usr/local/bin/arm-none-eabi-gcc - broken
CMake Error at /usr/local/Cellar/cmake/3.19.7/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "/usr/local/bin/arm-none-eabi-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/maclob01/Documents/mbed-tools-2/mbed-os-example-blinky/cmake_build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/local/bin/ninja cmTC_19e4d && [1/2] Building C object CMakeFiles/cmTC_19e4d.dir/testCCompiler.c.obj
    [2/2] Linking C executable cmTC_19e4d
    FAILED: cmTC_19e4d 
    : && /usr/local/bin/arm-none-eabi-gcc   CMakeFiles/cmTC_19e4d.dir/testCCompiler.c.obj -o cmTC_19e4d   && :
    /usr/local/Cellar/arm-gcc-bin@10/10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: /usr/local/Cellar/arm-gcc-bin@10/10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): in function `exit':
    exit.c:(.text.exit+0x2c): undefined reference to `_exit'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  mbed-os/tools/cmake/app.cmake:21 (enable_language)
  CMakeLists.txt:10 (include)


-- Configuring incomplete, errors occurred!
See also "/Users/maclob01/Documents/mbed-tools-2/mbed-os-example-blinky/cmake_build/CMakeFiles/CMakeOutput.log".
See also "/Users/maclob01/Documents/mbed-tools-2/mbed-os-example-blinky/cmake_build/CMakeFiles/CMakeError.log".
maclob01@C02CL7CDLVDL mbed-os-example-blinky % 

maclobdell avatar Mar 23 '21 18:03 maclobdell

The documentation is outdated. The build folder is not cmake_build anymore, but contains the target and the compiler options given to mbed-tools configure. Check your cmake_build directory to find where mbed_config.cmake is located and provide that path to -B.

Furthermore the current system does not allow providing C_C(XX)_COMPILER flags. You just have to add your compiler path to PATH. This is an open issue: https://github.com/ARMmbed/mbed-os/issues/14446

boraozgen avatar Mar 23 '21 18:03 boraozgen

interesting. thanks for the help!. This command worked.

cmake -S . -B cmake_build/K64F/develop/GCC_ARM -GNinja -DCMAKE_BUILD_TYPE=debug

Awesome! Building is so much faster with the new tools!

I definitely recommend updating the documentation to clarify this. Also, it would be good to mention how the tools select the compiler from the path and you might run into trouble if you have multiple compilers installed.

maclobdell avatar Mar 23 '21 19:03 maclobdell

I left this open because I do think it would be good to update the documentation to clarify things. I will leave it up to the maintainers to decide to close it or not.

maclobdell avatar Apr 22 '21 14:04 maclobdell

Hi @maclobdell We've updated the "How to use CMake" docs at https://github.com/ARMmbed/mbed-os-5-docs/blob/development/docs/tools/mbed_cli_2/use.md#build-the-project-with-cmake-advanced

Patater avatar Apr 23 '21 08:04 Patater

@Patater I have two gcc like follow, so how can I focus the second , I have used -D CMAKE_C_COMPILER=xxx -D CMAKE_CXX_COMPILER=xxx

C:\Program Files (x86)\GNU Tools ARM Embedded\6 2017-q2-update\bin\arm-none-eabi-g++.exe C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2020-q4-major\bin\arm-none-eabi-g++.exe

Layty avatar Jan 10 '24 08:01 Layty