LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 02-09-2009, 07:42 AM   #1
toredo
Member
 
Registered: Feb 2009
Posts: 83

Rep: Reputation: 25
Compile Code for ARM-Processor


Hello,

Sorry i'm not very well in english, i hope you can read the text.

I use a SAM9-L9260 with an AT91SAM9260-Processor. I installed a Debian-Linux as Operating System. I can communicate with RS232 (Serial) or over Ethernet with SSH (i use Putty).

The Standart-Tools on Linux works fine, there are no problems.

But now, i want to compile a Hello-World-Program for my Developer-Board.

test.c (The code works on my Desktop-Debian):
Code:
#include <stdio.h>
main()
{
 printf("Hello World \n");
}
I found 2 ways to do this:

First Way: Crosscompile the Code

I Installed some packages to crosscompile the code:
Code:
arm-binutils 2.16-2    The GNU binary utilities for cross targeting
arm-elf-gcc  2.95.3-2  arm-elf C cross compiler
arm-gcc      3.4.4-2   The GNU C compiler for cross targeting ARM f
arm-glibc    2.3.5-2   The GNU C Library for cross targeting ARM fr
arm-kernel   2.6.10-2  The Linux kernel for ARM (AT91RM9200)
and also an "arm-linux-gcc".

First i compiled is with arm-elf-gcc:
Code:
arm-elf-gcc test.c
Output (Sry, but its German):
Code:
test.c:1: stdio.h: Datei oder Verzeichnis nicht gefunden
In english (self translated):
Code:
test.c:1: stdio.h: Can't find file or dictionary
Ok, that dont work.

Then i compiled it with the "arm-linux-gcc":
Code:
arm-linux-gcc test.c
There is no outpur, so i think it worked.

Then i copied the file on my SAM9-L9260, over Putty i executed the file:
Code:
./a.out
Output:
Code:
-bash: ./a.out: No such file or directory
I don't understand this error, because the file "a.ou" exists... (if i press "Tab" in Putty it autocomplete a.out)

Ok, this way does not work.

Second Way: Compile on the Target-System

On the target is a gcc, so i thinked i can compile code with this.

I executed:
Code:
gcc-4.1 test.c
Output:
Code:
test.c:1:19: error: stdio.h: No such file or directory
test.c: In function 'main':
test.c:4: warning: incompatible implicit declaration of built-in function 'printf'
It does not work too...



I don't know how i can compile code for my SAM9-L9260, pleae help me.

Thx, regards
toredo
 
Old 02-09-2009, 01:39 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by toredo View Post
Then i copied the file on my SAM9-L9260, over Putty i executed the file:
Code:
./a.out
Output:
Code:
-bash: ./a.out: No such file or directory
I don't understand this error, because the file "a.ou" exists... (if i press "Tab" in Putty it autocomplete a.out)
You didn't say how you transferred a.out to your target host, but perhaps the file permissions were not preserved. If the file does not have execute permissions, try
Code:
chmod +x a.out
on the target host.
You can avoid the use of a.out as an output filename quite easily:
Code:
gcc -o test test.c
--- rod.
 
Old 02-12-2009, 01:38 AM   #3
toredo
Member
 
Registered: Feb 2009
Posts: 83

Original Poster
Rep: Reputation: 25
thx for the answer.

The rights of the a.out-file were ok.

But thanks for the -o Parameter.

regards toredo
 
Old 02-12-2009, 10:41 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I'm not sure how/if bash detects whether a specified binary executable is a valid object file for the host it is to run on, but given your difficulties in building the object code, I would try to ascertain that your a.out (or test, now that you know about -o ) is valid for the target host. If you have 'file', you can use it to determine something about your executable.
Code:
file ./a.out
An sample ARM binary of mine shows:
Code:
ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.18, dynamically linked(uses shared libs), not stripped
Try to do this on the target host, if possible, to account for possible mangling of the object file during file transfer. BTW, how are you doing the file transfer? Are you sure that the file is being transferred intact? Since you say you used putty, I imagine you are using Windows, which may require special treatment of binary files to prevent translation of newlines, etc.

--- rod.

Last edited by theNbomr; 02-12-2009 at 10:46 AM.
 
Old 02-13-2009, 07:29 AM   #5
toredo
Member
 
Registered: Feb 2009
Posts: 83

Original Poster
Rep: Reputation: 25
Hello,

Thanks, now i found a valid crosscompiler (crosstool-linux-gcc-4.0.1-glibc-2.3.5.tar.bz2), and the new output of the "file"-Command is:
Code:
./hello: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), for GNU/Linux 2.4.3, not stripped
On the target-System i installed three packages, because the binary didn't work correctly:
Code:
libc6_2.3.6.ds1-13etch9_arm.deb
linux-kernel-headers_2.6.18-7_arm.deb
libc6-dev_2.3.6.ds1-13etch9_arm.deb
Now my HelloWorld works perfectly, but i have another problem:
The compiler only knows some packages, of course not all. But if i want to work with more packages, but i can't compile Binary using this packages.

How can i add them to the compiler's "brain"?

To install them on the target is no problem.

Thanks for the answers.


regards toredo
 
Old 02-13-2009, 08:01 AM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Different question, so I suggest starting a new thread. My short answer is that I used Kegel's crosstool to generate my cross toolchain. I am now looking at the newer crosstool-ng. Both are easily found online.
--- rod.
 
Old 01-30-2012, 07:43 AM   #7
wiguna149
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Hello everyone,

I am really new to this forum and i get the same problem with toredo.

i am using linux 10.04 in my PC and i am using arm-linux-gcc to compile my helloworld program.
the command is :"arm-linux-gcc -o hello hello.c".
the output file "hello" is transferred with ftp. before transferring, i use command "bin" as in the tutorial i followed.
To run the program, i am using ssh and type "./hello". the reply is like in toredo's case.
i compare my output file with the one from example. the file size is different. the example version is about 3 kb and my compiled version is about 5 kb.
is there anything wrong with my compiler? i am using arm-linux-gcc version 4.4.3.
 
Old 01-30-2012, 07:49 AM   #8
wiguna149
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
i have changed the permission with "chmod +x hello"
 
Old 01-30-2012, 09:48 AM   #9
Ninaeve
LQ Newbie
 
Registered: Jan 2012
Posts: 21

Rep: Reputation: Disabled
Try this

Hi, I solved with
$ arm-linux-gcc -o outputfile.exe inputfile.c
$ arm-linux-strip outputfile.exe
$ chmod +x outputfile.exe
$ ./outputfile.exe

because I had problems with the output file extension.
The arm-linux-gcc makes a outputfile.exe ^_^

Maybe you must have the right cross-compiler (check it out)
Break a leg
 
Old 01-30-2012, 09:56 PM   #10
wiguna149
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Hi ninaeve
this still does not work on me..
i have tried using the makefile from example given and it give the same problem when executed.
i am using arm-linux-gcc v 4.4.3.
by the way, what is the use of arm-linux strip?
is there any effect for different file extension in linux?

toredo said thad we can compile our c program in the target processor. how can i do that? because i can't find any gcc in my linux.
 
Old 01-31-2012, 12:33 AM   #11
qwerty4061
Member
 
Registered: Nov 2011
Posts: 31

Rep: Reputation: Disabled
Hi toredo,
Try this, this might fix your problem you stated in the first post

Code:
"arch"-linux-gcc -static "source-file.c"
This will generate a bigger executable as as this is statically linked, but it will take care of your problems of missing libraries. Static linking is probably not a good idea for your final product, but you can use it until you install all the required libraries on your target.

Quote:
by the way, what is the use of arm-linux strip?
The strip utility removes the debugging symbols from your executable, thus reducing its size
 
Old 01-31-2012, 12:38 AM   #12
qwerty4061
Member
 
Registered: Nov 2011
Posts: 31

Rep: Reputation: Disabled
I didn't see that it was a 3 year old thread... wiguna149 maybe you can try what i told in my previous post
 
Old 01-31-2012, 01:26 AM   #13
wiguna149
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
hi qwerty4061
i realized that the first post was old enough and i am still getting the problem nowadays.i was a little embarassed when i realized this.

by the way my problem was solved just now. i have just changed my arm-linux-gcc version from 4.4.3 to 3.2.2 and it is working now for the helloworld program. tonight i will make some test for another program.

Thanks everyone
 
Old 03-01-2012, 09:18 AM   #14
dlopezsk
LQ Newbie
 
Registered: Feb 2012
Posts: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by wiguna149 View Post
hi qwerty4061
i realized that the first post was old enough and i am still getting the problem nowadays.i was a little embarassed when i realized this.

by the way my problem was solved just now. i have just changed my arm-linux-gcc version from 4.4.3 to 3.2.2 and it is working now for the helloworld program. tonight i will make some test for another program.

Thanks everyone
Hi friends,

I've same problem with you, but I use armv5tel, I use this form:

armv5tel-redhat-linux-gnueabi-gcc readFiles.c -o provaFile -static

But another file just compile until 2007 is :ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped.

Althought that I've the same armv5tel, the file would like to compile it return :
ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped


The difference that I can see (SYSV) and for GNU/Linux 2.6.14, because I use virtual machine with a fedora 13.

I need to know ,what happen? Thanks
 
Old 03-02-2012, 02:50 AM   #15
dlopezsk
LQ Newbie
 
Registered: Feb 2012
Posts: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by dlopezsk View Post
Hi friends,

I've same problem with you, but I use armv5tel, I use this form:

armv5tel-redhat-linux-gnueabi-gcc readFiles.c -o provaFile -static

But another file just compile until 2007 is :ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped.

Althought that I've the same armv5tel, the file would like to compile it return :
ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped


The difference that I can see (SYSV) and for GNU/Linux 2.6.14, because I use virtual machine with a fedora 13.

I need to know ,what happen? Thanks

I solvent, I install arm-gp2x-linux-gcc helloWorld.c -o hello -static
 
  


Reply



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
par2 for arm processor steve51184 Linux - Software 8 02-04-2009 01:18 PM
Compile the linux2.6.14.1 for arm must ues the arm-linux-gcc-3.4.4? frankyue Linux - Embedded & Single-board computer 2 12-20-2008 07:28 AM
porting Fedora Linux on ARM processor Mahesha kempegowda Linux - Newbie 1 11-18-2008 05:52 PM
porting Fedora Linux on ARM processor Mahesha kempegowda Linux - Newbie 1 11-18-2008 01:37 AM
video grabbing application for ARM processor ravi_chobey Linux - Embedded & Single-board computer 3 08-07-2008 09:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 04:03 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
Open Source Consulting | Domain Registration