Programming C/C++ in Angstrom

I got my first beagleboard (revision C4) in the mail a few days ago
and so far I have learned a lot but now I am hitting a brick wall.
What I have right now is a development computer running Ubuntu 9.10
which I have used to format the sd cards and put the angstrom demo
image on it. The demo image boots fine but the gui is killing the cpu
because I don't have the gpu drivers installed. My use case does not
require a gui, everything that I want to be done can be done from a
console program.

I program in C# and Java right now but I will be moving to C or C++ to
program the beagleboard because it seems easier but I can't seem to
find a tutorial describing how to compile and run the simplest code.

Here's what I have

Angstrom - Console no gui running on the beagleboard

I want to start simple so lets say I want to compile a "hello world"
program on my pc and then load it to the beagleboard. I know that a
cross compiler is needed to compile it for the ARM architecture but I
found NO tutorials or explanations just people posting links to
websites with very vague (if any) instructions.

I just downloaded the C6000 Code Generation Tools but have absolutely
no idea on how to use it.

Could someone please give me a nice explanation on how I would go
about writing the hello world program, compiling it for the
beagleboard, and then actually running it on the beagleboard!

If all you need is a cross compiler (assuming your board is setup and Linux actually runs on it), download the code sourcery command line tools (cross compiler) from here:
http://www.codesourcery.com/sgpp/lite/arm/portal/package5385/public/arm-none-linux-gnueabi/arm-2009q3-67-arm-none-linux-gnueabi.bin

The installer itself gives you a nice GUI (that’ll lead you through the installation).

Assuming you run the installation (say, you choose to install it in /opt/arm-2009q3/), add the (bin) folder to your path and you should now have a working compiler toolchain.

Assume you create a file (hello.c), you can compile it using:
$ arm-none-linux-gnueabi-gcc -o hello_arm hello.c

Now you can download this binary (hello_arm) and run it in your Beagle board.

All this is assuming that the kernel running on your beagle board is configured for proper input/output (say via serial cable, or via networked X).

Goodluck…

Regards,
-Srived.

Hello,

I own a Beagleboard Rev C that is running Basic Karmic (9.10)
Beagleboard xfce4 version. In my case, to compile a simple hello world
program I ran this on my terminal (in Beagleboard) to install gcc
libraries and everything "sudo apt-get install build-essential" after
this I was able to build and compile a hello world program.

Create a file (in terminal):
1. sudo vi hello.cpp
2. type:
#include <iostream>
int main()
{
   std::cout << "Hello, Beagleboard" << std::endl;
   return 0;
}
3. Compile with : g++ hello.cpp -o hello
4. Run it with: ./hello

That's it, I am not sure if this is relevant to you question but I
hope it helps.

Thank you,

Abraham

[…]

Could someone please give me a nice explanation on how I would go
about writing the hello world program, compiling it for the
beagleboard, and then actually running it on the beagleboard!

As Abraham suggested, you can compile it directly on the BeagleBoard, or
you can do cross compile your program. In contrast to SV I would suggest
to follow [1] and for bigger projects use OpenEmbedded and create a
recipe for your program.

Thanks,

Paul

[1] http://linuxtogo.org/gowiki/CompilingYourOwnCode

Thanks for the replies!

I am starting to understand it now, in a little bit I will try to get
the hello world program running.

Hi Paul,
I am curious to know if code-sourcery toolchain has any problems that are serious enough to cause issues for bigger projects? I thought it is fairly standard.

Regards,
SV.

Dear SV,

    I am curious to know if code-sourcery toolchain has any problems
that are serious enough to cause issues for bigger projects? I thought
it is fairly standard.

Sorry, I did not want to apply that there are any issues. I just got
into BeagleBoard and the cross compiling world and am pretty satisfied
with OpenEmbedded and did not look yet into code sourcery’s tools.

I think though that it was mentioned on this list that when using a
distribution based on OpenEmbedded like Ångström, it might be easier
using OpenEmbedded framework.

Thanks and sorry for the confusion,

Paul

Oh ok. Thank you for clarifying.

Have fun,
-Sri

Your toolchain needs to match the one used to compile the distro you are using. If it doesn't match you're opening yourself to a world of pain.
And no, angstrom isn't currently using the CSL toolchain.

regards,

Koen

Could someone please give me a nice explanation on how I would go
about writing the hello world program, compiling it for the
beagleboard, and then actually running it on the beagleboard!

  1. On host m/c , i have arm cross compiler installed .

  2. Following is the params what i used to compile my helloworld.c

arm-none-linux-gnueabi-gcc -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wdeclaration-after-statement -Wold-style-definition -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -Os -static -o $2 $1

  1. Move the compiled and built binary helloworld.out to SDCARD.

  2. From beagle board console, run ./helloworld.out

You do know -Os is horribly broken on virtually all gcc based compilers that support cortex-a8?

arm-none-linux-gnueabi-gcc -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wdeclaration-after-statement -Wold-style-definition -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -Os -static -o $2 $1

You do know -Os is horribly broken on virtually all gcc based compilers that support cortex-a8?

Thanks for update . I never used the above for huge piece of code , but tried a hello world, so i am unaware.