Précédent   Forum des professionnels en informatique > Systèmes > Linux
Linux Forum d'entraide sur le système Linux. Avant de poster -> Tutoriels Linux, F.A.Q Linux
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 04/02/2011, 19h24   #1
Membre habitué
 
Inscription : mars 2009
Messages : 208
Détails du profil
Informations forums :
Inscription : mars 2009
Messages : 208
Points : 104
Points : 104
Par défaut vieux hello Linux

Bonjour à tous les Linuxiens :
j'ai récement sorti de mes cartons un vieux bouquin sur le système XWindow;
Je vous livre le code du premier programme exemple :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
#include </usr/X11R6/include/X11/Xlib.h>
#include </usr/X11R6/include/X11/Xutil.h>
 
char	hello[]="How do you do ?";
char	texte_clic[]="-yau de poêle!";
 
int main (int argc,char **argv)
{
	Display *canal_aff;
	Window *fenetre;
	GC contx_graph;
	XEvent evenem;
	KeySym touche;
	XSizeHints infos_fen;
	XWMHints infos_WM;
	int test_boucle,ecran,i;
	unsigned long couleur_AVplan,couleur_ARRplan;
	char frappe[10];
 
	canal_aff=XOpenDisplay("");
	ecran=DefaultScreen(canal_aff);
 
	couleur_ARRplan=WhitePixel(canal_aff,ecran);
	couleur_AVplan=BlackPixel(canal_aff,ecran);
 
	infos_fen.x=200;
	infos_fen.y=300;
	infos_fen.width=350;
	infos_fen.height=250;
	infos_fen.flags=PPosition | PSize;
	infos_WM.flags=InputHint;
	infos_WM.input=True;
 
	fenetre=XCreateSimpleWindow(canal_aff,DefaultRootWindow(canal_aff),
			infos_fen.x,infos_fen.y,
			infos_fen.width,infos_fen.height,5,
			couleur_AVplan,couleur_ARRplan);
	XSetStandardProperties(canal_aff,fenetre,hello,hello,None,
			argv,argc,&infos_fen);
	XSetWMHints(canal_aff,fenetre,&infos_WM);
 
	contx_graph=XCreateGC(canal_aff,fenetre,0,0);
	XSetBackground(canal_aff,contx_graph,couleur_ARRplan);
	XSetForeground(canal_aff,contx_graph,couleur_AVplan);
 
	XSelectInput=(canal_aff,fenetre,
		ButtonPressMask | KeyPressMask | ExposureMask);
 
	XMapRaised(canal_aff,fenetre);
 
	test_boucle=0;
	while(test_boucle == 0)
	{
		XNextEvent(canal_aff,&evenem);
		switch(evenem.type)
		{
			case Expose:
				if(evenem.xexpose.count == 0)
					XDrawImage(evenem.xexpose.display,
					 evenem.xexpose.window,contx_graph,
				 	 50,50,hello,strlen(hello));
		       		break;
			case MappingNotify:
				XRefreshKeyboardMapping(&evenem);
				break;
			case ButtonPress:
				XDrawImageString(evenem.xbutton.display,
				 evenem.xbutton.window,contx_graph,
		 		 evenem.xbutton.x,evenem.xbutton.y,
				 texte_clic,strlen(texte_clic));
	       			break;
			case KeyPress:
				i=XLookupString(&evenem,frappe,10,&touche,0);
				if(i==1 && frappe[0]=='q') test_boucle=1;
				break;
		}
	}
	XFreeGC(canal_aff,contx_graph);
	XDestroyWindow(canal_aff,fenetre);
	XCloseDisplay(canal_aff);
 
	exit(0);
}
Malheureusement la compilation pose problème :
Code :
1
2
3
4
5
6
7
8
9
10
11
 
hello.c: In function `main':
hello.c:37: warning: assignment makes pointer from integer without a cast
hello.c:39: warning: passing arg 2 of `XSetStandardProperties' makes integer from pointer without a cast
hello.c:40: warning: passing arg 2 of `XSetWMHints' makes integer from pointer without a cast
hello.c:42: warning: passing arg 2 of `XCreateGC' makes integer from pointer without a cast
hello.c:47: error: invalid lvalue in assignment
hello.c:49: warning: passing arg 2 of `XMapRaised' makes integer from pointer without a cast
hello.c:64: warning: passing arg 1 of `XRefreshKeyboardMapping' from incompatible pointer type
hello.c:73: warning: passing arg 1 of `XLookupString' from incompatible pointer type
hello.c:79: warning: passing arg 2 of `XDestroyWindow' makes integer from pointer without a cast
Apparement les fonctions de bibliothèques renaclent sur les types d'arguments ?! Où est le problème ?
exe2bin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/02/2011, 19h37   #2
Expert Confirmé Sénior
 
Avatar de frp31
 
Homme francois
Ingénieur systèmes et réseaux
Inscription : juillet 2006
Messages : 3 534
Détails du profil
Informations personnelles :
Nom : Homme francois
Âge : 35
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Ingénieur systèmes et réseaux
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : juillet 2006
Messages : 3 534
Points : 7 743
Points : 7 743
déjà faudrait vérifier les fonctions en question dans les .h pour voir, mais il semble bien que la piste soit là bonne, peut être que le code est tout simplement trop vieux, suffit alors de le modérniser tout en gardant cette base.

j'en dirai pas plus parce que ca fait longtemps que j'ai pas codé sur un langage compilé.
frp31 est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/02/2011, 19h41   #3
Membre habitué
 
Inscription : mars 2009
Messages : 208
Détails du profil
Informations forums :
Inscription : mars 2009
Messages : 208
Points : 104
Points : 104
Justement c'est ça qui m'inquiète : les types semblent corrects !!
exe2bin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/02/2011, 11h13   #4
Membre expérimenté
 
Avatar de cboudy
 
Ingénieur informatique industrielle
Inscription : avril 2006
Messages : 382
Détails du profil
Informations personnelles :
Localisation : France

Informations professionnelles :
Activité : Ingénieur informatique industrielle

Informations forums :
Inscription : avril 2006
Messages : 382
Points : 526
Points : 526
tu as essayé de mettre des casts pour que le compilo râle moins ?
le problème vient surement des options par défaut du compilo qui doit être moins permissif qu'à l'époque (cc vs gcc ...)
cboudy est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/02/2011, 23h04   #5
Membre confirmé
 
Avatar de quetzacoatl
 
Inscription : janvier 2011
Messages : 168
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 168
Points : 202
Points : 202
J'ai remarqué un problème:
Citation:
XSelectInput=(canal_aff,fenetre,
ButtonPressMask | KeyPressMask | ExposureMask);
correspondant à:
Citation:
hello.c:47: error: invalid lvalue in assignment
Soit il manque un nom de fonction, soit le "=" est en trop
quetzacoatl est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/02/2011, 11h37   #6
Membre habitué
 
Inscription : mars 2009
Messages : 208
Détails du profil
Informations forums :
Inscription : mars 2009
Messages : 208
Points : 104
Points : 104
Bien vu quetzacoatl !!
G remédié au problème mais bien evidement c maintenant le linker qui
rechigne et voilà pourquoi :
Le bouquin lance le compilateur comme ceci : "cc hello.c -lX11 -o hello"
C bien gentil tout ça mais j'utilise la RedHat 10.0 et X11 y en a pas ou alors
pas à la même place mais de toute façon il va falloir que j'indique le répertoire ;
Ensuite se pose le problème des liens : est ce que -lX11 peut pointer sur
un lien ou pas ?! et les droits du fichier X11 sont root bien sur alors est que
je peux quand même l'utiliser à partir d'un autre compte ....
Résultat le linker ne reconnaît pas les fonctions XMachinChose car je n'arrive
pas à lier la biblothèque
Quelle misère
exe2bin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/02/2011, 21h56   #7
Membre expérimenté
 
Avatar de cboudy
 
Ingénieur informatique industrielle
Inscription : avril 2006
Messages : 382
Détails du profil
Informations personnelles :
Localisation : France

Informations professionnelles :
Activité : Ingénieur informatique industrielle

Informations forums :
Inscription : avril 2006
Messages : 382
Points : 526
Points : 526
des fois il faut rajouter des chemins au path pour trouver les libs (genre -L/usr/X11R6/lib)
il faut ptêt rajouter d'autres libs aussi (Xt ou Xm de tête alors je suis pas trop sur)
cboudy est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/02/2011, 15h00   #8
Membre habitué
 
Inscription : mars 2009
Messages : 208
Détails du profil
Informations forums :
Inscription : mars 2009
Messages : 208
Points : 104
Points : 104
Bon jvais essayer ça
exe2bin est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 08h29.


 
 
 
 
Partenaires

Hébergement Web