IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Systèmes de compilation Discussion :

[Makefile] Pas de règle pour la cible main.c


Sujet :

Systèmes de compilation

  1. #1
    Membre régulier
    Inscrit en
    Août 2004
    Messages
    201
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 201
    Points : 83
    Points
    83
    Par défaut [Makefile] Pas de règle pour la cible main.c
    J'essaye de creer un makefile pour faciliter la compilation. Voila a quoi ressemble mon fichier "makefile":

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    rent:           main.o SumArray.o
                    gcc *.o -o rent
     
    main.o:         main.c rent.h
                    gcc -Wall -c main.c
     
    SumArray.o:     SumArray.c rent.h
                    gcc -Wall -c SumArray.c
    Le programme "rent.c":

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
     
    double SumArray ( double [ ], int );
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
     
    #define SQUARE(x)   ((x)*(x))
     
    // Defing a specific format for the listing instead of using
    // multiple tabs
     
    #define W "15"
    #define Z "14"
    #define U "%"Z"s"
    #define S "%"W"s"
    #define F1 "%"W".1f"
    #define F2 "%"W".2f"
     
    /*  SumArray is a fonction that calculates the sum of any
        array when it is called */
     
    #include "rent.h"
     
    double SumArray (double a[], int n)
    {
       int c;
       double sum = 0;
     
       for (c = 0; c < n; c++)
       {
          sum += a[c];
       }
       return sum;
    }
     
    #include "rent.h"
     
    int main (void)
    {
       // Two arrays that are the ones provided from the file
       double filearray1[14], filearray2[14],
     
       // Three arrays to store in them further calculations
              filearray3[14], filearray4[14],
              filearray5[14];
     
       // Setting counter to 0
       size_t r = 0;
       FILE *fp;
     
       // File that we will read from
       char fname[] = "rent2.dat";
       if ((fp = fopen (fname, "r")) == NULL)
       {
          printf ("Unable to open %s.\n", fname);
          exit (1);
       }
     
       printf (S S "\n", "Rent","Income");
       printf (U U U U U "\n", "X","Y","X^2","Y^2","XY");
     
       while (r < (sizeof filearray1/sizeof *filearray1 )
       &&   fscanf (fp, "%lf%lf\n", &filearray1[r], &filearray2[r]) != EOF)
       {
          // The three arrays which contain calculations:
          // Squaring the first array read and storing it in another one
          filearray3[r] = SQUARE (filearray1[r]);
     
          // Doing the same thing with the second one
          filearray4[r] = SQUARE (filearray2[r]);
     
          // Product of the first two arrays
          filearray5[r] = filearray1[r] * filearray2[r];
     
          // Priting everything
          printf (F1 F1 F2 F2 F2 "\n",
                  filearray1[r], filearray2[r], filearray3[r],
                  filearray4[r], filearray5[r]);
                  r++;
     
       }
     
       // Summing all the arrays and storing results
       // in new double variables so that further
       // will be easier
       double SumX = SumArray (filearray1,r),
              SumY = SumArray (filearray2,r),
              SumXX = SumArray (filearray3,r),
              SumYY = SumArray (filearray4,r),
              SumXY = SumArray (filearray5,r);
     
       printf (S S S S S "\n", "------","--------","---------","-------------","-----------");
     
       // Printing the total at the end of each array
       printf (F1 F1 F1 F1 F1"\n", SumX, SumY, SumXX, SumYY, SumXY);
     
       printf("\n\n\t\t\t Press ENTER to Continue");
       getchar();
     
       /* Coefficient of correlation calculations */
     
       // Number of elements contained in each array
       int N = 14;
     
       // Variable of the coefficient
       double coef;
     
       // Declaring two others so that the formula is easier
       double coef1, coef2;
     
       // Calculation of the coefficient using formula provided
       coef1 = N*SumXY - (SumX)*(SumY);
       coef2 = sqrt((N*SumXX - SumX*SumX)*(N*SumYY - SumY*SumY));
       coef = coef1/coef2;
     
       printf ("\n\n\t +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ ");
       printf ("\n\t | Coefficient of correlation is: | ");
       printf ("\n\t |         r = + %.2lf             | ", coef);
       printf ("\n\t +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ \n");
     
       /* Regression equations calculation */
       // Variables needed for the equation
       double a, b, b1, b2, avgX, avgY;
     
       // Averaging X and Y
       avgX = SumX/N;
       avgY = SumY/N;
     
       // Calculating b
       b1 = SumXY - N*avgX*avgY;
       b2 = SumXX - N*avgX*avgX;
       b = b1/b2;
     
       // Calculating a
       a = avgY - b*avgX;
     
      // Plugging a and b and priting the equation
      printf("\n\t Regression equation is: \n");
      printf("\t =-=-=-=-=-=-=-=-=-=-=-= \n");
      printf("\n\t Yc  =  a  +  bX =  %.2lf  +  %.2lfX\n", a, b);
     
      printf("\n\t( a = %.6lf , b = %.6lf )\n\n", a, b);
     
      /* Stand error of estimate */
     
      double Sy;
     
      Sy = (SumYY - (a*SumY + b*SumXY))/N;
      Sy = sqrt (Sy);
     
      printf("\t +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+ ");
      printf("\n\t | The Standard error of estimate: |");
      printf("\n\t |         Sy = +/- $%.2lf       |", Sy);
      printf("\n\t +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+\n");
     
      printf("\n\t\t\t Press ENTER to continue \n");
      getchar();
     
      // Variables needed for prediction of the income
      double rent, choice, income, lower, upper;
     
      do
      {
            printf("\n\nEnter a rent amount (to quit enter 0) : ");
            scanf("%lf", &rent);
     
             if(rent > 0)
            {
                    income = a + (b*rent);
                    lower = income - Sy;
                    upper = income + Sy;
     
                    printf("\n\n\t Rent \t\t Lower Limit \t Predicted Income \t Upper Limit \n");
                    printf("\n\t$ %.2lf  \t  %.2lf     \t   %.2lf  \t\t %.2lf \n", rent, lower, income, upper);
            }
     
            else if ( rent < 0 )
            {
                    printf("\nError! Entry not valid, try again.\n");
            }
       }
            while (rent != 0);
            return 0;
    }
    Quand je tape: "make" dans la ligne de commande, une erreur dit que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    make: *** No rule to make target `main.c', needed by `main.o'.  Stop.
    Merci de votre aide.

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    865
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 865
    Points : 1 069
    Points
    1 069
    Par défaut
    Euh... est-ce que tu as un fichier main.c ? Si tu n'en as pas c'est normal et je dirais que oui puisque tu définis main() dans rent.c.
    Par contre, il faudrait que tu compiles rent.c

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    rent:           rent.o SumArray.o
                    gcc *.o -o rent
     
    rent.o:         rent.c rent.h
                    gcc -Wall -c rent.c
     
    SumArray.o:     SumArray.c rent.h
                    gcc -Wall -c SumArray.c

  3. #3
    Membre régulier
    Inscrit en
    Août 2004
    Messages
    201
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 201
    Points : 83
    Points
    83
    Par défaut
    Non je n'ai pas de fichier main.c, j'ai just rent.c et makefile.

    Meme apres avoir corriger makefile:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    rent.o:         rent.c rent.h
                    gcc -Wall -c rent.c
     
    SumArray.o:     SumArray.c rent.h
                    gcc -Wall -c SumArray.c
    Une erreure du meme type:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    make: *** No rule to make target `main.o', needed by `rent'.  Stop.

  4. #4
    Membre éprouvé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    865
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 865
    Points : 1 069
    Points
    1 069
    Par défaut
    Une erreur s'était glissée dans mon Makefile. C'est corrigé.

    Est-ce que tu comprends les modifications ?

  5. #5
    Membre régulier
    Inscrit en
    Août 2004
    Messages
    201
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 201
    Points : 83
    Points
    83
    Par défaut
    Citation Envoyé par aoyou Voir le message
    Une erreur s'était glissée dans mon Makefile. C'est corrigé.

    Est-ce que tu comprends ce que tu fais ?
    J'etais confus d'avoir vu main.o, je l'avais remplace par rent.c avant que tu nous reponde. mais l'erreur est toujours presente:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    make: *** No rule to make target `rent.h', needed by `rent.o'.  Stop.
    Alors que j'ai bien inclus "rent.h" avant chaque fonction dans rent.c...

  6. #6
    Membre éprouvé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    865
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 865
    Points : 1 069
    Points
    1 069
    Par défaut
    Alors que j'ai bien inclus "rent.h" avant chaque fonction dans rent.c...
    Aucun rapport. J'espère que tu ne l'inclus pas avant chacune des fonctions par contre...

    Il y a t'il un fichier rent.h ?

    Peux-tu me lister tous les fichiers dans le répertoire du Makefile ?

  7. #7
    Membre régulier
    Inscrit en
    Août 2004
    Messages
    201
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 201
    Points : 83
    Points
    83
    Par défaut
    c'est bon j'ai regle le probleme.

    Il fallait avoir un header file, chose que je n'avais pas

    Merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. make pas de règle pour fabrique la cible clean
    Par sousoux dans le forum Linux
    Réponses: 11
    Dernier message: 09/12/2014, 10h20
  2. Pas de règle pour fabriquer la cible (Makefile)
    Par arsene87 dans le forum Débuter
    Réponses: 8
    Dernier message: 11/06/2014, 09h39
  3. Makefile : pas de règle pour fabriquer la cible « moc »
    Par allchimiste dans le forum Débuter
    Réponses: 1
    Dernier message: 18/06/2013, 14h33
  4. Réponses: 3
    Dernier message: 15/02/2009, 10h27
  5. [postfix] make tidy: Pas de règle pour fabriquer la cible « tidy »
    Par rvfranck dans le forum Administration système
    Réponses: 5
    Dernier message: 23/06/2007, 16h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo