Advance Toolchain for Linux on Power cross-compiler
The Advance Toolchain provides cross-compilers that run on Intel x86 and generate code for Power that helps teams to start developing for Power without having immediate access to a POWER server. The cross-compiler provides a way to compile programs for POWER by using a x86 (i386) or x86-64 (amd64) computer, helping teams to start developing for POWER without having access to a server in the early development phase.
IBM Advance Toolchain for Linux on Power 16.0-5 is now available! Learn more
Install the cross-compiler
Build a sample program
GNU wget is a small program that highlights the important problems when cross compiling a certain software: it depends on libraries provided by the Advance Toolchain cross-compiler and external libraries.
In this example, we build GNU wget
for POWER little endian by using a x86 computer with the Advance Toolchain cross-compiler.
Copy headers and libraries
First, copy all necessary libraries and headers to a certain directory. This example uses the following libraries and headers:
- Headers:
${HOME}/wget/include
- Libraries:
${HOME}/wget/lib
In this case, ${HOME} is a shell variable holding the path of my home directory.
For GNU wget
, we need to provide some OpenSSL
libraries and Zlib
. Both of them are available in the Advance Toolchain native compiler. However, the list of necessary libraries might vary according to the project. If you don't know well the project, you can use the following tools in order to identify the list of libraries they use:
ldd <executable> rpm -q --requires -p <package.rpm> dpkg-deb -f <package.deb> | grep "Depends:"
Usually the list of libraries necessary to build a project is the same across all processor architectures. So, you might use the previous commands against an executable or package compiled for another processor.
Here is the list of files required in order to build wget
:
$ ls -1 ${HOME}/wget/include/ openssl/ zconf.h zlib.h $ ls -1 ${HOME}/wget/lib/ libcrypto.so libcrypto.so.1.0.0 libssl.so libssl.so.1.0.0 libz.so libz.so.1 libz.so.1.2.6
Make sure the libraries are compiled for the target processor. If they don't match, you don't be able to use them. You might use readelf -h
to verify this information:
$ /opt/at7.1/bin/powerpc64le-linux-gnu-readelf -h ${HOME}/wget/lib/libz.so.1.2.6 ... Data: 2's complement, little endian ... Machine: PowerPC64 ...
Build
With the header files and libraries in place, the system is ready to start the build. So, create a separate build directory:
mkdir ${HOME}/wget/build && cd ${HOME}/wget/build
After you enter the separate build directory, it's possible to configure the build by running:
CC=/opt/at7.1/bin/powerpc64le-linux-gnu-gcc \ CFLAGS="-I${HOME}/wget/include" \ LDFLAGS="-L${HOME}/wget/lib" \ ../wget-1.15/configure \ --host=powerpc64le-linux \ --with-ssl=openssl
Where:
- The variable
CC
specifies which compiler to use. In this case, Advance Toolchain 7.1 cross-compiler for POWER little endian. Cross-compilers usually have a prefix in their program name to clearly indicate they don't generate executable code for the current processor. In this case, the prefix is "powerpc64le-linux-gnu-
". This rule applies to all programs, for example:g++
,gdb
,ld
,as
, etc - The variable
CFLAGS="-I"
indicates where the compiler finds the header files. - The variable
LDFLAGS="-L"
indicates where the linker finds the libraries. - This
../wget-1.15
is the directory where wget source code is available. In this case, it is the same of${HOME}/wget/wget-1.15
. - The option
--host=powerpc64le-linux
indicates this code runs on POWER little endian. - The option
--with-ssl=openssl
forces wget to useOpenSSL
.
Finally, build wget by using the make command:
make
After you run this command, you'll find the program available at ${HOME}/wget/build/src/wget
.
You can now copy it to a POWER little endian system with the Advance Toolchain runtime package installed and run it.
Frequently asked questions (FAQ)
Get answers to some of the most frequently asked questions about working with the cross-compiler.