Compilation avec argc,argv???(urgent)

bonjour,
voilà je n'arrive pas à compiler ni à exécuter mon programme
j'effectue les commandes suivantes :
gcc -c bonjour.c
puis ./bonjour
mais ca ne fonctionne pas

voilà mon prog

# include <X11/Xlib.h>
# include <X11/Xutil.h>

char hello[]= {"comment aller vous?"};
char texte_clic[]= {"super genial"};

main (argc,argv)
{
int argc;
char **argv;

Display *canal_aff;

Window *fenetre;
GC contx_graph;
int ecran;
int i;

XEvent evenem;
KeySym touche;

XSizeHints infos_fen;
XWMHints infos_WM;
unsigned long couleur_AVplan, couleur_ARRplan;
char frappe[10];
int test_boucle;

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,(int) fenetre, hello,hello, None, argv, argc,
&infos_fen);

XSetWMHints(canal_aff,(int) fenetre,&infos_WM);

contx_graph= XCreateGC (canal_aff, (int)fenetre,0,0);
XSetBackground(canal_aff,contx_graph,couleur_ARRplan);
XSetForeground(canal_aff,contx_graph,couleur_AVplan);

XSelectInput(canal_aff,(int) fenetre, ButtonPressMask | KeyPressMask | ExposureMask);

XMapRaised (canal_aff,(int) fenetre);

test_boucle=0;
while (test_boucle == 0)
{

XNextEvent (canal_aff,&evenem);
switch (evenem.type)
{

case Expose :
if (evenem.xexpose.count == 0)
XDrawImageString(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, strln(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,(int) fenetre);
XCloseDisplay(canal_aff);
exit(0);
}

6 réponses

  1. Modérateur
    Hello,
    J'ai pu compiler ton source et l'exécuter:
    J'ai ajouté une ligne
    #include <strings.h>
    pour la fonction strlen ( et non strlndans une des lignes)
    J'ai compilé sous Debian Woody avec

    $gcc test.c -o test -I /usr/X11R6/include/X11/
    -L /usr/X11R6/lib -lX11
    ( en une ligne )

    test.c: In function `main':
    test.c:93: warning: assignment makes pointer from integer without a cast
    test.c:165: warning: passing arg 1 of `XRefreshKeyboardMapping' from incompatible pointer type
    test.c:187: warning: passing arg 1 of `XLookupString' from incompatible pointer type

    Voilà , super génial s'affiche dans la fenêtre.
    The software said "Requires Windows98, Win2000, or better,
    So I installed Unix.
    0
    1. Salut jisisv,

      j'ai tapé, sur linux, la ligne de commande que tu m'as envoyée pour compiler. Ensuite je tape ./bonjour.c et le programme ne s'exécute pas .
      voilà ce qu'il me dit

      : command not found
      ./bonjour.c: char:command not found
      :command not found
      ./bonjour.c:char command not found
      :command not found
      :command not found
      ./bonjour.c: line 8: syntax error near unexpected token '(argc,argv)'
      'bonjour.c:line 8:'main(argc,argv)

      Comment dois je faire pour exécuter mon programme???
      Merci
      0
  2. Modérateur
    Hi,
    Oui, j'changé la définition de main en quelque chose de standard

    main (int argc, char *argv[])
    {
    Display *canal_aff;
    Window *fenetre;
    ....
    }

    The software said "Requires Windows98, Win2000, or better,
    So I installed Unix.
    0
    1. Modérateur
      Salut,
      Si l'exécutable de sortie s'appelle bonjour,
      tu lances ./bonjour
      (gcc bonjour.c -o bonjour ......)

      Johan
      The software said "Requires Windows98, Win2000, or better,
      So I installed Unix.
      0
      1. Modérateur
        Bonjour,
        Voici la version fonctionnelle du code et la commande de compilation que j'ai utilisées...

        #include <X11/Xlib.h>
        #include <X11/Xutil.h>
        #include <strings.h>
        char hello[]= {"comment aller vous?"};
        char texte_clic[]= {"super genial"};

        main (int argc, char *argv[])
        {
        Display *canal_aff;
        Window *fenetre;
        GC contx_graph;
        int ecran;
        int i;

        XEvent evenem;
        KeySym touche;
        XSizeHints infos_fen;
        XWMHints infos_WM;

        unsigned long couleur_AVplan, couleur_ARRplan;
        char frappe[10];
        int test_boucle;

        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,(int) fenetre, hello,hello, None, argv, argc, &infos_fen);
        XSetWMHints(canal_aff,(int) fenetre,&infos_WM);

        contx_graph= XCreateGC (canal_aff, (int)fenetre,0,0);
        XSetBackground(canal_aff,contx_graph,couleur_ARRplan);
        XSetForeground(canal_aff,contx_graph,couleur_AVplan);
        XSelectInput(canal_aff,(int) fenetre, ButtonPressMask | KeyPressMask | ExposureMask);
        XMapRaised (canal_aff,(int) fenetre);

        test_boucle=0;
        while (test_boucle == 0)
        {
        XNextEvent (canal_aff,&evenem);
        switch (evenem.type)
        {
        case Expose :
        if (evenem.xexpose.count == 0)
        XDrawImageString(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,(int) fenetre);
        XCloseDisplay(canal_aff);
        exit(0);
        }

        Compilation:
        gcc test.c -o test -I /usr/X11R6/include/X11/ -L /usr/X11R6/lib -lX11

        The software said "Requires Windows98, Win2000, or better,
        So I installed Unix.
        0
        1. Merci!!!!! Ca marche Le problème en fait c'était que je lançais le mauvais exécutable . Je lançais ./bonjour.c au lieu de ./bonjour!!

          pourrais tu juste m'expliquer la ligne pour compiler:
          gcc bonjour.c -o bonjour -I /usr/X11R6/include/X11/ -L /usr/X11R6/lib -lX11

          pourquoi fait tu apelle à "/usr/X11R6/include/X11" et "/usr/X11R6/lib" : Ce ne sont pas les deux mêmes librairies????
          Xlib.h et Xutils.h ne sont elles pas toutes deux dans le répertoire: /usr/include/X11??
          et que veut dire "-lX11?
          Merci
          0
          1. Modérateur
            Bonjour,
            L'option -I indique l'emplacement de recherche des ficjhiers include (sous la forme d'un chemin séparé par ":" )
            -L indique l'endroit où se trouve les bibliothèques nécessaires
            pour compiler l'exécutable.

            Regarde man gcc .

            Johan
            The software said "Requires Windows98, Win2000, or better,
            So I installed Unix.
            0