cross compile for user space on ubuntu for bone?

I am finding dozens of posts on cross compiling, but they are either about compiling the kernel, not user space apps, or they say “I just cross compile” with no helpful details, or they say “use Eclipse” (or some other IDE).

I’d like to avoid installing and getting up to speed on yet another IDE, and it seems it “ought to” be straight forward to just use gcc and set appropriate flags for the target architecture, but I am not able to find any description of exactly how to do this.

So, is there a step by step how-to somewhere on setting up a cross compile environment that a) is not strictly telling you how to simply re-build the kernel, and b) does not amount to “install my_favorite_ide”?

I did find one post from last July (?) that ended with essentially this same question, but it was never answered.

Thanks,

Mickey

Mickey,

Is there a reason you need to use Ubuntu? I find Angstrom to run
cleaner and has an online building tool.

http://www.angstrom-distribution.org/
http://narcissus.angstrom-distribution.org/

Cheers
-Nat

Building the rootfs is not the issue, that is well in hand.
Cross compiling userspace apps is what I am looking for guidance on.
I have a number of userspace apps that will eventually be run on the BeagleBone.
They are currently being developed, have already been developed, or have been ported from Windows, in Ubuntu running on a desktop development machine.
I do not want to further complicate things by using different distributions on the various different hardware involved.

Thanks

If they have already been ported to Ubuntu/x86, then just install the
ubuntu armel/armhf gcc cross tools..

armel: sudo apt-get install gcc-arm-linux-gnueabi
armhf: sudo apt-get install gcc-arm-linux-gnueabihf

For a simple cross build, (as long as you don't use any system
libraries) just change "CC=gcc" to:

armel: CC=arm-linux-gnueabi-gcc"
armhf: CC=arm-linux-gnueabihf-gcc"

However if your using native system libraries, you'll also need the
"armel/armhf" version of that library when building... Hence this goes
from simple to complicated and there's not a lot of wiki/forum/etc on
it..

with later versions of ubuntu you can do: sudo apt-get install
libxyz:armhf (or something like that, look up "multiarch")..

Regards,

Why not just native compile on the bone?

Yes, it may be slower, but you'll avoid the exciting (it's not) fun
(it's not) of cross library dependencies. Plus, you can build things
like Perl which have generally been a real pain to cross build.

Or, if you have some money, buy a Panda (or other higher powered ARM
board) and use it as a build machine.

-Andrew

If they have already been ported to Ubuntu/x86, then just install the

ubuntu armel/armhf gcc cross tools…

armel: sudo apt-get install gcc-arm-linux-gnueabi
armhf: sudo apt-get install gcc-arm-linux-gnueabihf

For a simple cross build, (as long as you don’t use any system
libraries) just change “CC=gcc” to:

armel: CC=arm-linux-gnueabi-gcc"
armhf: CC=arm-linux-gnueabihf-gcc"

However if your using native system libraries, you’ll also need the
“armel/armhf” version of that library when building… Hence this goes
from simple to complicated and there’s not a lot of wiki/forum/etc on
it…

with later versions of ubuntu you can do: sudo apt-get install
libxyz:armhf (or something like that, look up “multiarch”)…

Thanks Robert - I hoped it would not be much more complicated than this. Since I am using your scripts to build the kernel I already have gcc-arm-linux-gnueabihf installed. I set CC=gcc-arm-linux-gnueabihf
then I do:
gcc -Werror hello_arm.c -o hello_arm

And I do get an executable, but when I move it over to the Bone and try to execute it I get “Cannot execute binary file”.
This sounds to me that It may not have compiled for the arm after all, but I am also using stdio.h and it may not have found the correct one. Some of my reading suggests that I may have to fiddle with the environment so that the arm library files are always correctly used. (“sysroot”?)

I see that there is a /usr/bin/arm-linux-gnueabihf and that its ./include contains stdio.h and other library files, but I don’t know how to confirm or ensure that I am pointing at this or at the correct compiler version.

Why not just native compile on the bone?

Yes, it may be slower, but you’ll avoid the exciting (it’s not) fun
(it’s not) of cross library dependencies. Plus, you can build things
like Perl which have generally been a real pain to cross build.

Or, if you have some money, buy a Panda (or other higher powered ARM
board) and use it as a build machine.

-Andrew

I can see that it may not be fun, but from what I have heard, it can be a LOT slower. I appreciate the idea of a hardware solution, but yet another platform (a Panda) is not in the budget, and we do have lots of PC’s. I discovered that the canutils which ship with Angstrom are not on Ubuntu by default, and have not succeeded in trying to natively compile those. I think I’d like to minimize the number of development machines I’m using. Also, I’ve gotten spoiled having several large monitors and 8 or 10 terminals and windows to work in, and I don’t think either the Beagle or Panda is going to do that for me.

Thanks

Mickey

If they have already been ported to Ubuntu/x86, then just install the

    ubuntu armel/armhf gcc cross tools..

    armel: sudo apt-get install gcc-arm-linux-gnueabi
    armhf: sudo apt-get install gcc-arm-linux-gnueabihf

    For a simple cross build, (as long as you don't use any system
    libraries) just change "CC=gcc" to:

    armel: CC=arm-linux-gnueabi-gcc"
    armhf: CC=arm-linux-gnueabihf-gcc"

    However if your using native system libraries, you'll also need the
    "armel/armhf" version of that library when building... Hence this goes
    from simple to complicated and there's not a lot of wiki/forum/etc on
    it..

    with later versions of ubuntu you can do: sudo apt-get install
    libxyz:armhf (or something like that, look up "multiarch")..

Thanks Robert - I hoped it would not be much more complicated than this. Since I am using your scripts to build the kernel I already have gcc-arm-linux-gnueabihf installed. I set
CC=gcc-arm-linux-gnueabihf
then I do:
gcc -Werror hello_arm.c -o hello_arm

This is invoking the native compiler. Use the cross tools like this:
   % ${CC} -Werror hello_arm.c -o hello_arm

I just confirmed that my hello world did compile for the PC, not the arm, by running it on the PC. Presumably it would have failed there if it had in fact been compiled for the ARM. Should have tried that immediately.

Mickey

After further exploring /user/arm-linux-gnueabihf I got it:

“arm-linux-gnueabihf-gcc -Werror hello_arm.c -o hello_arm”

compiles and runs as expected on the Bone.

Not

“gcc-arm-linux-gnueabihf -Werror hello_arm.c -o hello_arm”

Thanks all - now I’ll try with something a bit more ambitious…

Mickey

It can be a lot slower, yes. If you're building simple, small
programs, native compiling isn't that much slower that you'll notice.
If you're building big things that are conducive to cross compiling
without lots of effort, you can win back lots of time. It's just that
many programs aren't conducive to cross compiling and fixing them so
they are is sometimes quite an involved process.

If you have an ssh server on your beagle, you can open as many
terminals as you want on your nice big desktop monitors :wink:

-Andrew

Hi Mikey, Try: After setting CC=gcc-arm-linux-gnueabihf ${CC} -Werror hello_arm.c -o hello_arm Alternatively call the arm GCC directly: gcc-arm-linux-gnueabihf -Werror hello_arm.c -o hello_arm Cheers, Jack.