主页 Swift UNIX C Assembly Go Plan 9 Web MCU Research Non-Tech

Errors and solutions when building Raspberry Pico cross-compilation environment

2023-08-10 | MCU | #Words: 646

This blog likes a manual used to record possible errors.

No install step for ‘ELF2UF2Build’

There are two reasons for this error:

  1. An incorrect or incomplete version of arm-none-eabi-gcc is installed;
  2. Failure to use the correct C/C++ compiler resulted in the compiled elf2uf2 being incorrect;

The first reason

It usually occurs when use brew. In this case, use the following commands to uninstall and clean up the content installed by brew:

# Uninstall arm-none-eabi-gcc
$ brew uninstall arm-none-eabi-gcc
# Remove some according content downloaded
$ brew cleanup arm-none-eabi-gcc
# brew install binary file to /usr/local/bin/ in default. Although have been uninstalled, but maybe have some remaining files. Remove manually
$ sudo rm /usr/local/bin/arm-none-eabi-*

Now we can download from offical website:

Open Arm GNU Toolchain Downloads, use the on-page search function to search for “macOS” because there are so many links. There are so many links just under macOS:

There are so many links just under macOS

Select the link in AArch32 bare-metal target (arm-none-eabi) for your corresponding platform (processor architecture) and click to download. Choose AArch32 because the Arm Cortex M0 included in RP2040 is 32-bit, which means AArch32. If you download AArch64 bare-metal target (aarch64-none-elf), it will cannot compile successfully.

The second reason

The solution to this problem is to set the environment variables CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to let cmake know which compiler specfied. Otherwise, the local Clang will be selected as the compiler by default, but this local Clang cannot compile the program we need.

There are two solutions at this time.

Set in Shell configuration file

At this time, you can choose to add the following statements to your Shell configuration file (the following paths need to be modified according to your own settings):

export CC="/usr/local/bin/arm-none-eabi-gcc"
export CXX="/usr/local/bin/arm-none-eabi-g++"

or

export CMAKE_C_COMPILER="/usr/local/bin/arm-none-eabi-gcc"
export CMAKE_CXX_COMPILER="/usr/local/bin/arm-none-eabi-g++"

Then use source to activate the change, or you can close the Terminal window and re-open it.

Set in CMakeLists.txt

You can set it in the CMakeLists.txt configuration file in the CMake project. Add the following commands before project(...):

set(CMAKE_C_COMPILER /usr/local/bin/arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER /usr/local/bin/arm-none-eabi-g++)

Then clear the directory build and re-build.

fatal error: cannot read spec file ‘nosys.specs’: No such file or directory,

fatal error: cannot read spec file 'nosys.specs': No such file or directory shows that the nosys.specs file cannot be read. This may be because when nosys.specs needs to be read, nosys. specs is not ready yet. This error usually occurs when using make to finally build the binary file. The solution is to use make -j4 (personal test is at least 4) to process 4 tasks at the same time, so this error disappears.

Link error

This error has many kinds of reasons, the mainly appearance is: compilation errors, check the information and find it caused by ld or arm-none-eabi-ld. This is because the -isysroot parameter used by linker is wrong. Generally, this error is caused by link to the local SDK instead of the .so file required by Linux.

This kind of error requires adding the following commands before project(...) in the CMakeLists.txt of project (the following paths need to be modified according to your own settings):

set(CMAKE_SYSROOT /usr/local/lib/arm-none-eabi/bfd-plugins/libdep.so)

Then empty the build, and re-build.

I couldn’t remember all errors, because I didn’t take notes. I will complement later when I remembered them.

I hope these will help someone in need~