LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   Compile Code for ARM-Processor (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/compile-code-for-arm-processor-703336/)

toredo 02-09-2009 07:42 AM

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

theNbomr 02-09-2009 01:39 PM

Quote:

Originally Posted by toredo (Post 3437103)
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.

toredo 02-12-2009 01:38 AM

thx for the answer.

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

But thanks for the -o Parameter.

regards toredo

theNbomr 02-12-2009 10:41 AM

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.

toredo 02-13-2009 07:29 AM

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

theNbomr 02-13-2009 08:01 AM

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.

wiguna149 01-30-2012 07:43 AM

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.

wiguna149 01-30-2012 07:49 AM

i have changed the permission with "chmod +x hello"

Ninaeve 01-30-2012 09:48 AM

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

wiguna149 01-30-2012 09:56 PM

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.

qwerty4061 01-31-2012 12:33 AM

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

qwerty4061 01-31-2012 12:38 AM

:o I didn't see that it was a 3 year old thread... :mad: wiguna149 maybe you can try what i told in my previous post

wiguna149 01-31-2012 01:26 AM

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

dlopezsk 03-01-2012 09:18 AM

Quote:

Originally Posted by wiguna149 (Post 4589081)
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

dlopezsk 03-02-2012 02:50 AM

Quote:

Originally Posted by dlopezsk (Post 4615993)
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


All times are GMT -5. The time now is 04:27 AM.