LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-31-2009, 08:52 AM   #1
tomas632
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Rep: Reputation: 0
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
 
Old 12-31-2009, 09:19 AM   #2
ernie
Senior Member
 
Registered: Nov 2001
Location: Toledo, Ohio - USA
Distribution: Mageia 1
Posts: 1,079
Blog Entries: 4

Rep: Reputation: 70
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,
 
Old 12-31-2009, 09:23 AM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,892
Blog Entries: 27

Rep: Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182
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.

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 12-31-2009, 05:32 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 17,092

Rep: Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551
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.
 
Old 12-31-2009, 05:43 PM   #5
allanf
Member
 
Registered: Sep 2008
Location: MN
Distribution: Gentoo, Fedora, Suse, Slackware, Debian, CentOS
Posts: 98
Blog Entries: 1

Rep: Reputation: 19
Quote:
Originally Posted by tomas632 View Post
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).
 
Old 01-01-2010, 10:09 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,892
Blog Entries: 27

Rep: Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182
Hi,

Quote:
Originally Posted by allanf View Post
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 View Post
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.

 
Old 01-02-2010, 07:03 AM   #7
tomas632
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by allanf View Post
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?
 
Old 01-02-2010, 08:04 AM   #8
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,892
Blog Entries: 27

Rep: Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182
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?



EDIT: BTW, look at 'ARM architecture'.

Last edited by onebuck; 01-02-2010 at 08:09 AM. Reason: add link
 
Old 01-02-2010, 01:25 PM   #9
tomas632
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
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?
 
Old 01-02-2010, 05:32 PM   #10
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,892
Blog Entries: 27

Rep: Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182Reputation: 2182
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.

 
Old 01-02-2010, 06:38 PM   #11
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 01-02-2010 at 06:40 PM.
 
Old 01-04-2010, 09:25 AM   #12
tomas632
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
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.
 
Old 01-16-2010, 11:23 PM   #13
allanf
Member
 
Registered: Sep 2008
Location: MN
Distribution: Gentoo, Fedora, Suse, Slackware, Debian, CentOS
Posts: 98
Blog Entries: 1

Rep: Reputation: 19
Quote:
Originally Posted by tomas632 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Cross Platform Compatible Binary File Open Read Problem MatrixNAN Programming 6 09-18-2009 03:37 AM
Cross-Platform file Encryption/Protection. AGazzaz Linux - Software 1 05-30-2008 09:59 AM
Cross Compiling 2.4.34 to run on a Pentium R (II) 266 MHz dwhitney67 Linux - Kernel 1 02-24-2008 04:22 PM
file/directory sharing -cross platform emp1953 Linux - Software 4 02-19-2008 08:07 AM
What file format to use for cross-platform network? postitnote100 Linux - Networking 1 06-24-2006 12:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration