Setting Up a Cross-Complier

This assumes that a cross-compiler is setup are part of you PATH variable.

For example, here we are using the GNU Arm Embedded Toolchain and can test it's installed by doing:

$ arm-none-eabi-gcc -v
...
gcc version 5.4.1 20160609 (release) [ARM/embedded-5-branch revision 237715] (GNU Tools for ARM Embedded Processors)

To get Scons to use the cross-compiler rather than the host compiler, we need to replace certain construction variables in the build environment with cross-build specific names. The major ones of interest are:

  • AS : The assembler
  • AR : The static library archiver
  • CC : The C complier
  • CXX : The C++ complier
  • LINK : The linker
  • PROGSUFFIX : The suffix used for executable file names
  • RANLIB : The archive indexer

There are many other SConscript variables, but this is the key set for building.

To replace, simple use the .Replace function on the Environment variable, e.g.

env = Environment(ENV = os.environ)

env.Replace(AS="arm-none-eabi-as")
env.Replace(AR="arm-none-eabi-ar")
env.Replace(CC="arm-none-eabi-gcc")
env.Replace(CXX="arm-none-eabi-g++")
env.Replace(LINK="arm-none-eabi-g++")                # predefined is 'arm-none-eabi-gcc'
env.Replace(PROGSUFFIX=".elf")
env.Replace(RANLIB="arm-none-eabi-ranlib")

Now when scons is invoked, it will use the arm-none-eabi-gcc compiler instead of the host based one.

Obviously, all the target specific pre-processor, compiler and linker flags still need configuring for your specific build, but you should end up with a .elf file. See Custom Builders for how to generate a .bin file.

results matching ""

    No results matching ""