Difference between revisions of "Trash Fr:HelloWorld"

From ArmadeusWiki
Jump to: navigation, search
(Redirecting to HelloWorld)
 
Line 1: Line 1:
Sur cette page, vous apprendrez à créer votre première application C pour votre carte Armadeus
+
#REDIRECT[[HelloWorld]]
 
+
==Code source==
+
* Premièrement, prenez votre éditeur/IDE préféré et créez le programme suivant:
+
<source lang="C">
+
#include <stdio.h>
+
#include <stdlib.h>
+
+
int main(int argc, char *argv[])
+
{
+
    printf( "APF9328 says: Hello World ! ;-)\n" );
+
    exit(0);
+
}
+
</source>
+
* Enregistrez le sous ''hello.c''
+
 
+
==Compilation==
+
Le compilateur croisé est installé dans ''armadeus/buildroot/build_arm/staging_dir/bin/'' et est appelé ''arm-linux-gcc''
+
Il y a 2 façosn de l'utiliser:
+
* soit en ajoutant ''armadeus/buildroot/build_arm/staging_dir/bin/'' à votre variable d'environnement ''PATH'' et en appelant ensuite ''arm-linux-gcc'' au lien de ''gcc''
+
* ou en appelant directement ''armadeus/buildroot/build_arm/staging_dir/bin/arm-linux-gcc''
+
 
+
Ainsi, pour compiler votre petit programme, faites (ici hello.c a été enregistré dans le répertoire armadeus/target/demos/):
+
[host demos]$ ../../buildroot/build_arm/staging_dir/bin/arm-linux-gcc -o hello hello.c
+
 
+
==Fonctionnement==
+
Copiez votre exécutable ''hello'' sur votre carte soit par TFTP ou NFS.
+
===TFTP===
+
Assurez-vous d'avoir le serveur TFTP d'installé. [[Connection_with_U-Boot_on_Linux#TFTP_server| sinon, c'est expliqué ici]]<br>
+
Copiez ''hello'' dans votre répertoire TFTP:
+
[host demos]$ cp hello /tftpboot/
+
Chargez votre exécutable sur votre cible (ici l'IP de mon hôte est 192.168.0.2):
+
# tftp -g -r hello -l /usr/bin/hello 192.168.0.2
+
Donnez lui les droits exécutable, si perdus durant le transfert TFTP:
+
# chmod a+x /usr/bin/hello
+
Lancez-le:
+
# /usr/bin/hello
+
APF9328 says: Hello World ! ;-)
+
#
+
 
+
Maintenant vous en êtes capable ! ;-)
+
 
+
===NFS===
+
Assurez-vous d'avoir le serveur NFS installé, [[Network_Configuration| sinon, c'est expliqué ici]]<br>
+
Je considère que votre pilote NFS est accessible depuis ''/mnt/host''
+
Lancez votre programme:
+
[target]# /mnt/host/hello
+
 
+
==En les mettant tous ensembles dans un Makefile==
+
Vous pouvez mettre compiler et copier votre programme dans un''Makefile'' pour faire les choses proprement:
+
CC=arm-linux-gcc
+
CFLAGS=-W -Wall
+
LDFLAGS=
+
EXEC=hello
+
SRC= $(wildcard *.c)
+
OBJ= $(SRC:.c=.o)
+
+
all: $(EXEC)
+
+
hello: $(OBJ)
+
    $(CC) -o $@ $^ $(LDFLAGS)
+
+
%.o: %.c
+
    $(CC) -o $@ -c $< $(CFLAGS)
+
+
.PHONY: clean install
+
+
clean:
+
    rm -rf *.o
+
    rm -f $(EXEC)
+
+
install: all
+
    cp -f $(EXEC) /tftpboot/
+
 
+
'''!! Si vous faites un copié&collé de la commande précédente, n'oubliez pas de les TABS de chaque cible(les Makefiles utilisent des TABS et non des  ESPACES) !! Dans ce cas, make se plaindra d'une séparateur manquant à la ligne 11'''
+
 
+
Ensuite, faites juste:
+
[host demos]$ make clean install
+
 
+
==Liens==
+
* [http://www.handhelds.org/minihowto/porting-software.html Things to know when porting x86 software to ARM]
+
* [http://gl.developpez.com/tutoriel/outil/makefile/ Les Makefiles, comment ça marche ?]
+
* [http://www.advancedlinuxprogramming-fr.org/doku.php Livre en ligne: Programmation Linux Avancée]
+
 
+
{{LanguageBar|HelloWorld|HelloWorld|HelloWorld}}
+

Latest revision as of 11:16, 10 April 2013

Redirect to: