Clang cross compilation

From Dmz-portal

Jump to: navigation, search

Contents

Prerequisites

This document describes how to use Clang 3.3 (and newer) to produce MIPS code using CodeSourcery Toolchain. Let's assume that a MIPS toolchain is installed in the $MIPS folder (i.e. mips-linux-gnu-gcc is in the $MIPS/bin folder). Clang supports the following options affect MIPS code generation: -mips16, -micromips, -msoft-float. To select big-endian / little-endian, pass -target mips-linux-gnu / -target mipsel-linux-gnu. To select 32-bit / 64-bit code generation, pass -target mips-linux-gnu / -target mips64-linux-gnu. Some examples are below.

Test case

Here is a C++ test case:

#include <iostreams>

int main()
{
  std::cout << "Hello, World!" << std::endl;
  return 0;
}

Little-endian 32-bit

% clang -target mipsel-linux-gnu -gcc-toolchain $MIPS main.cc

Run a.out to check results:

% qemu-mipsel -L $MIPS/mips-linux-gnu/libc/el ./a.out
Hello, World!

Big-endian 32-bit

% clang -target mips-linux-gnu -gcc-toolchain $MIPS main.cc

Run a.out to check results:

% qemu-mips -L $MIPS/mips-linux-gnu/libc ./a.out
Hello, World!

Little-endian 64-bit

% clang -target mips64el-linux-gnu -gcc-toolchain $MIPS main.cc

Big-endian 64-bit

% clang -target mips64-linux-gnu -gcc-toolchain $MIPS main.cc

Little-endian MIPS16

% clang -target mipsel-linux-gnu -gcc-toolchain -mips16 $MIPS main.cc
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox