Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile Hello World program for PowerPC

Tags:

c

gcc

powerpc

I have a Dreambox 500 which on Wikipedia says has a PCP processor which is PowerPC:

$ cat /proc/cpuinfo
processor: 0
cpu: STBx25xx
clock: 252MHz
Review: 9.80 (pvr 5151 0950)
bogomips: 250.36
Machine: Dream Multimedia Dreambox TV
plb bus clock: 63MHz

I would normally install GCC but it has low storage on it and I need to compile a program for it.

I've heard GCC can compile powerpc but I had no luck doing so.

Example this code

#include <stdio.h>

int main()
{
    printf("Hello World!\n");

    return 0;
}

And I use this to compile

gcc example.c -mtune=powerpc

But it give this error

example.c:1:0 error: bad value (powerpc) for -mtune- switch
#include <stdio.h>
^

Thank you!

like image 662
Iamk Denok Avatar asked Aug 19 '15 20:08

Iamk Denok


2 Answers

You should use cross-compiler, because your target architecture differs from host one. Host is the architecture of your system (usually amd64 (x86_64) or i386 (x86_32)). And target arch is the arch on which your compiled program will run (powerpc in your case).

Many GNU/Linux distors provide crosscompilers as a separate packages. For example, for Ubuntu these packages are available:

sudo apt-get install gcc-4.8-powerpc-linux-gnu g++-4.8-powerpc-linux-gnu binutils-4.8-powerpc-linux-gnu

Packages above are for trusty. In later releases different GCC versions are available.

Then you can compile your program using powerpc-linux-gnu-gcc-4.8. Or you can set your environment variables CC and CXX to powerpc-linux-gnu-gcc-4.8 and powerpc-linux-gnu-g++-4.8 accordingly.

upd: I found crosscompiler toolchain for Dreambox 500 here, but it contains relatively old GCC (3.4).

In order to use it extract downloaded file to /opt/cross/dm500, add /opt/cross/dm500/cdk/bin to path via export PATH=$PATH:/opt/cross/dm500/cdk/bin and use gcc from here with appropriate prefix.

like image 143
nightuser Avatar answered Oct 03 '22 01:10

nightuser


After being on a programming forum for a while, found a guy with the same problem, and after a while he found a way to fix it and I tried it and it works. The thing I have to do is

powerpc-gcc someprog.c -static

I have no idea what the -static does but it increases the executable file size and at the end it works!

like image 33
Iamk Denok Avatar answered Oct 03 '22 02:10

Iamk Denok