LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cross compiling a file to run on a linux platform (https://www.linuxquestions.org/questions/linux-newbie-8/cross-compiling-a-file-to-run-on-a-linux-platform-779064/)

tomas632 12-31-2009 07:52 AM

cross compiling a file to run on a linux platform
 
Hi Guys, I have a single board computer that I am using for a university project, which runs linux and currently has this installed. However the PC I am using for writing software is running windows and I am trying to write a simple program, something as trivial as "hello world" that can be written in windows and then compiled and transferred to the linux platform to be executed. However to be honest I don't have a clue how to do this. If anyone could offer any assistance on how to do this it would be greatly appreciated. Thanks
Tom

ernie 12-31-2009 08:19 AM

If you have enough hard drive space, install a VM program (I use Sunś Virtual Box here). Install a Linux distribution (perhaps the same one used at school) in the VM program. Make sure to install all appropriate development packages. Write your software using the Linux installation in the VM. Windows is not affected, and you can check that your software works correctly in the environment for which it was intended.

HTH,

onebuck 12-31-2009 08:23 AM

Hi,

Welcome to LQ!

To make things easier I would use a 'VM' (virtual machine). Get VMware, VirtualBox or whatever VM to use on the M$ based system to host a GNU/Linux. That way you could run, compile or whatever on the M$ host the Client GNU/Linux application. This way you could build on the GNU/Linux then move the build too your embed.
:hattip:
The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

jefro 12-31-2009 04:32 PM

You basically can't use windows to make binaries for linux. It could work for some apps. Almost all command line apps have a chance but any gui's get out of the question unless the using a cross platform building like maybe qt.

It is as above you have to run in linux to have any hope of success.

allanf 12-31-2009 04:43 PM

Quote:

Originally Posted by tomas632 (Post 3809896)
I have a single board computer that I am using for a university project, which runs linux and currently has this installed.

What processor is on the the single board computer? Even using a VM you still can have a problem is the processor is not an x86 (or relative). Does the single board computer have the development process present?

If so a ANSI or OSI C program can be transferred as source and compiled there. In the case of "Hello World" it could even be build and verified on the Windows machine but the binary is worthless on a Linux machine.

The OS and and the hardware are the two important properties (and in some cases the libraries also) in determining if an executable built on machine 'A' will be able to be run on machine 'B' (or if it needs to be build again for machine 'B'). Best to portability is to learn the standard language and code in it rather than using all of the non-standard stuff that many comanies add into their version of a language (to lock you into their build-chain and maybe even OS).

onebuck 01-01-2010 09:09 AM

Hi,

Quote:

Originally Posted by allanf (Post 3810328)
What processor is on the the single board computer? Even using a VM you still can have a problem is the processor is not an x86 (or relative). Does the single board computer have the development process present?

If so a ANSI or OSI C program can be transferred as source and compiled there. In the case of "Hello World" it could even be build and verified on the Windows machine but the binary is worthless on a Linux machine.

Not true. As long as the development system, compilers and such support the arch then builds for alien archs can be compiled and transported. There are a few distributions that have broad support. But it is true that most support x86 only.

Quote:

Originally Posted by allanf (Post 3810328)
The OS and and the hardware are the two important properties (and in some cases the libraries also) in determining if an executable built on machine 'A' will be able to be run on machine 'B' (or if it needs to be build again for machine 'B'). Best to portability is to learn the standard language and code in it rather than using all of the non-standard stuff that many comanies add into their version of a language (to lock you into their build-chain and maybe even OS).

False! If you have a build machine and wish to compile a kernel for another family on this host for another machine. The restrictions are the support of the compiler, libraries on the host. Let's stay with the i86. If you want to build a kernel for a i486 on a multi-core AMD Turion you would configure the '.config' file for the i486 based machine. Compile then move the kernel and modules for that kernel to the desired machine. The compilation on the host for the alien/embed kernel has nothing to do with the host's hardware, everything is determined by the '.config' file. 'cross-compiling' is done all the time.

Do you think people at M$ are sitting at a 'PC' to compile the kernel? NO! As long as the libraries, compilers and development support the desired arch then there is no reason that a build could not be built on a host for a build for another machine. Sure the embed must support the kernel you are building.

Heck, I was cross-compiling on a Z80 for a 8088 many years ago. With modern hardware the use of 'VM' can save the $$ for multi-platform development. This has opened to the masses the ability to utilize embeds without purchasing the IDE for the embed. Fortunately most embeds available to the populace are x86 based for the reason of software, hardware affordability. Sure there are other archs but most x86 entry systems are affordable, modifiable to the use of environments other than the manufactures. A lot the embeds manufactures use this too their advantage.

Sure, a lot of major manufactures would not utilize this method but would use the tools from embed systems to develop for their hardware. Companies like Ford, GE or the like would most likely utilize Intel's embed and IDE for the desired development embed. But, Joe's Garage Shop, could use a GNU/Linux OS as a client via a 'VM' on a M$ host to develop for a embed.

If the controller is exotic then one would be locked in to the manufactures tool-chain/IDE.

:hattip:

tomas632 01-02-2010 06:03 AM

Quote:

Originally Posted by allanf (Post 3810328)
What processor is on the the single board computer? Even using a VM you still can have a problem is the processor is not an x86 (or relative). Does the single board computer have the development process present?

If so a ANSI or OSI C program can be transferred as source and compiled there. In the case of "Hello World" it could even be build and verified on the Windows machine but the binary is worthless on a Linux machine.

The OS and and the hardware are the two important properties (and in some cases the libraries also) in determining if an executable built on machine 'A' will be able to be run on machine 'B' (or if it needs to be build again for machine 'B'). Best to portability is to learn the standard language and code in it rather than using all of the non-standard stuff that many comanies add into their version of a language (to lock you into their build-chain and maybe even OS).

The SBC I am using is here - http://www.glomationinc.com/product_9260.html
the processor being used is the atmel AT91SAM9260 ARM core, should it be ok cross compiling from windows to this platform?

onebuck 01-02-2010 07:04 AM

Hi,

Nice little board. What's the single unit price?

Quote:

excerpt from 'GESBC-9260/GESBC-9260B Embedded Single Board Computer';
Software support
* U-boot 1.3.3
* Linux 2.6.27
* Debian ARM Linux based distribution with GCC 4.2, Perl, binutils, and many other utilities for rapid native application development
* Linux cross development tool chain
* Support WinCE.net
From the above you've got the first step done for you. :)

What application do you have in mind?

:hattip:

EDIT: BTW, look at 'ARM architecture'.

tomas632 01-02-2010 12:25 PM

Hi, thanks for the quick response, I'm not too sure on the single unit price to be honest, because our university department ordered a small batch so that each project group could use one and this came straight out of our the department budget, sorry.

So with regards to your post above, yes I have the first step done. Currently I have a null modem cable connected to the device, which is linked to my windows pc. I can get the device to boot up as it has the linux kernel and u boot already installed. I can also access the file system and navigate around the system using ls, cd commands etc. (these are about the only commands I know!) So basically this is where I get stuck...

If I was doing this with a windows application and say a microchip PIC then I would write my c file, download the microchip compiler which would convert my c file to a hex file then program this to the device. I assume this is a similar process as to what I need to do here, but due to my non-existant linux knowledge I don't know where to go. If I wrote a basic c file in a text editor and saved it as .c file, I then cross compile it? How do I then transfer this to the device and in which location would I put it in order for it to run once the device boots up?

onebuck 01-02-2010 04:32 PM

Hi,

I was just curious about the single unit price. Most of the units are in the $40-$80 range. It's great the department has the project budget to cover the cost(s). While I was still at the University years ago, my budgets for senior projects was rather limited until we got sponsors for the projects. Another time & story.

As for the SBC you can still work on a bench machine and transport the programs to the embed. It sounds like you have a PC terminal linked to the embed system. Your SBC has Ethernet so why not use that? You could 'ssh' to the embed and work. You could 'scp' any data or information. The compile sessions would be a lot faster on a desktop PC rather than the embed.

:hattip:

paulsm4 01-02-2010 05:38 PM

Hi -

To add my $0.02 -

1. As some people noted, you *can* cross-compile for the ARM on Windows. That's what the Windows CE SDK does. You can also cross-compile for ARM/Linux on Windows. But I wouldn't.

2. Your best bet is to cross-compile on a PC/Linux for your ARM/Linux.

One way is to install Linux on a PC.

More convenient for you would be to install Linux on a *virtual PC* (like VMWare or VBox), then run your "Virtual Machine" (VM) under Windows.

Personally, I prefer VMWare. But VBox should be completely satisfactory, too. Both are available for Windows, both are free. VMWare Server and VMWare Player are both free downloads:

http://www.vmware.com

3. You don't even have to install Linux on the VM yourself - there are lots of free downloadable images ("Virtual Appliances") you can get. For example:

http://www.thoughtpolice.co.uk/

4. Your next big problem after deciding on a development OS (again, I recommend Linux, running under a VM) is setting up your cross-compiler tool chain for ARM/Linux.

It looks like Glomation already has everything you need available as free downloads on their web site:

http://www.glomationinc.com/support.html

5. The final step is learning how to actually USE the toolchain.

Two books I'd heartily recommend: get either or both of them:

Building Embedded Systems (O'Reilly):
http://www.amazon.com/Building-Embed...dp/0596529686/

Embedded Systems Primer (Hallinhan):
http://www.amazon.com/Embedded-Linux...dp/0131679848/

'Hope that helps .. PSM

tomas632 01-04-2010 08:25 AM

hi, I know people have suggested installing a linux distribution, but a lot of the time I am using university computers and cannot do this and so at the minute I am using windows. I have made some progress with this. I am using cygwin and a cross compiler toolchain from GNUARM called GCC 4.1. I have installed this and can compile my .c file into a .out file. I am then transferring the file with a USB stick. However when i come to run the file with the command ./a.out I get the following message...

/mnt/usb/ # ./a.out
Illegal instruction

I think this could be due to the compiler not compiling correctly or being the wrong one, but am not completely sure. If anyone could help with this then that would be great.

allanf 01-16-2010 10:23 PM

Quote:

Originally Posted by tomas632 (Post 3811530)
The SBC I am using is here - http://www.glomationinc.com/product_9260.html
the processor being used is the atmel AT91SAM9260 ARM core, should it be ok cross compiling from windows to this platform?

The arm processor would require a cross compiler and build stack. They probably have one for the Windows OS, I used to have a Linux box setup to build for an arm processor a few years ago. The arm is not an intel x86 compatible chip. Also the arm can be run in big endian or in little endian mode.

Try the google search:
http://www.google.com/linux?complete...in&btnG=Search

For links related to the ARM cross compiler tool chain. It takes more than a compiler to develop on a machine and deploy on another type of machine.


All times are GMT -5. The time now is 10:51 AM.