Problème compilation programme C

Fermé
elmod - 21 janv. 2009 à 15:50
 loupius - 21 janv. 2009 à 17:14
Bonjour,
j'ai un programme C et quand je compile j'ai des erreurs: voici le code

"openimage.c":

#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <mcimage.h>
#include <mccodimage.h>
#include <mcutil.h>

#define BUFFERSIZE 10000


struct xvimage * readimage(char *filename)

#undef F_NAME
#define F_NAME "readimage"
{
char buffer[BUFFERSIZE];
FILE *fd = NULL;
int32_t rs, cs, ds, ndgmax, N, i;
struct xvimage * image;
int32_t ascii;
int32_t typepixel;
int32_t c;
double xdim=1.0, ydim=1.0, zdim=1.0;
char *read;

#ifdef UNIXIO
fd = fopen(filename,"r");
#endif
#ifdef DOSIO
fd = fopen(filename,"rb");
#endif
if (!fd)
{
fprintf(stderr, "%s: file not found: %s\n", F_NAME, filename);
return NULL;
}

read = fgets(buffer, BUFFERSIZE, fd);
/* P5: raw byte bw ; P2: ascii bw */
/* P6: raw byte rgb ; P3: ascii rgb */
/* P8: raw int32_t 2d-3d == extension MC */
/* P9: raw float 2d-3d == extension MC */
/* PA: ascii float 2d-3d == extension LN */
/* PB: ascii int32_t 2d-3d == extension MC */
/* PC: raw double 2d-3d == extension MC */
/* PD: ascii double 2d-3d == extension LN */
/* P7: raw byte 3d : OBSOLETE - left for compatibility */
if (!read)
{
fprintf(stderr, "%s: fgets returned without reading\n", F_NAME);
return 0;
}

if (buffer[0] != 'P')
{ fprintf(stderr,"%s : invalid image format\n", F_NAME);
return NULL;
}
switch (buffer[1])
{
case '2': ascii = 1; typepixel = VFF_TYP_1_BYTE; break;
case '5':
case '7': ascii = 0; typepixel = VFF_TYP_1_BYTE; break;
case '8': ascii = 0; typepixel = VFF_TYP_4_BYTE; break;
case '9': ascii = 0; typepixel = VFF_TYP_FLOAT; break;
case 'A': ascii = 1; typepixel = VFF_TYP_FLOAT; break;
case 'B': ascii = 1; typepixel = VFF_TYP_4_BYTE; break;
case 'C': ascii = 0; typepixel = VFF_TYP_DOUBLE; break;
case 'D': ascii = 1; typepixel = VFF_TYP_DOUBLE; break;
default:
fprintf(stderr,"%s : invalid image format : P%c\n", F_NAME, buffer[1]);
return NULL;
} /* switch */

c = sscanf(buffer+2, "%d %d %d", &rs, &cs, &ndgmax);

if (c == 3) /* format pgm MatLab : tout sur une ligne */
{
ds = 1;
goto readdata;
}

do
{
read = fgets(buffer, BUFFERSIZE, fd); /* commentaire */
if (!read)
{
fprintf(stderr, "%s: fgets returned without reading\n", F_NAME);
return 0;
}
if (strncmp(buffer, "#xdim", 5) == 0)
sscanf(buffer+5, "%lf", &xdim);
else if (strncmp(buffer, "#ydim", 5) == 0)
sscanf(buffer+5, "%lf", &ydim);
else if (strncmp(buffer, "#zdim", 5) == 0)
sscanf(buffer+5, "%lf", &zdim);
} while (!isdigit(buffer[0]));

c = sscanf(buffer, "%d %d %d", &rs, &cs, &ds);
if (c == 2) ds = 1;
else if (c != 3)
{ fprintf(stderr,"%s : invalid image format\n", F_NAME);
return NULL;
}

read = fgets(buffer, BUFFERSIZE, fd);
if (!read)
{
fprintf(stderr, "%s: fgets returned without reading\n", F_NAME);
return 0;
}

sscanf(buffer, "%d", &ndgmax);

readdata:
N = rs * cs * ds;
image = allocimage(NULL, rs, cs, ds, typepixel);
if (image == NULL)
{ fprintf(stderr,"%s : alloc failed\n", F_NAME);
return(NULL);
}
image->xdim = xdim;
image->ydim = ydim;
image->zdim = zdim;

if (typepixel == VFF_TYP_1_BYTE)
{
if (ascii)
{
if (ndgmax == 255)
for (i = 0; i < N; i++)
{
fscanf(fd, "%d", &c);
UCHARDATA(image)[i] = (uint8_t)c;
} /* for i */
else if (ndgmax == 65535)
for (i = 0; i < N; i++)
{
fscanf(fd, "%d", &c);
UCHARDATA(image)[i] = (uint8_t)(c/256);
} /* for i */
else
{
fprintf(stderr,"%s : wrong ndgmax = %d\n", F_NAME, ndgmax);
return(NULL);
}
}
else
{
int32_t ret = fread(UCHARDATA(image), sizeof(char), N, fd);
if (ret != N)
{
fprintf(stderr,"%s : fread failed : %d asked ; %d read\n", F_NAME, N, ret);
return(NULL);
}
}
} /* if (typepixel == VFF_TYP_1_BYTE) */
else
if (typepixel == VFF_TYP_4_BYTE)
{
if (ascii)
{
for (i = 0; i < N; i++)
{
fscanf(fd, "%ld", &(ULONGDATA(image)[i]));
} /* for i */
}
else
{
int32_t ret = fread(ULONGDATA(image), sizeof(int32_t), N, fd);
if (ret != N)
{
fprintf(stderr,"%s : fread failed : %d asked ; %d read\n", F_NAME, N, ret);
return(NULL);
}
}
} /* if (typepixel == VFF_TYP_4_BYTE) */
else
if (typepixel == VFF_TYP_FLOAT)
{
if (ascii)
{
for (i = 0; i < N; i++)
{
fscanf(fd, "%f", &(FLOATDATA(image)[i]));
} /* for i */
}
else
{
int32_t ret = fread(FLOATDATA(image), sizeof(float), N, fd);
if (ret != N)
{
fprintf(stderr,"%s : fread failed : %d asked ; %d read\n", F_NAME, N, ret);
return(NULL);
}
}
} /* if (typepixel == VFF_TYP_FLOAT) */
else
if (typepixel == VFF_TYP_DOUBLE)
{
if (ascii)
{
for (i = 0; i < N; i++)
{
fscanf(fd, "%lf", &(DOUBLEDATA(image)[i]));
} /* for i */
}
else
{
int32_t ret = fread(DOUBLEDATA(image), sizeof(double), N, fd);
if (ret != N)
{
fprintf(stderr,"%s : fread failed : %d asked ; %d read\n", F_NAME, N, ret);
return(NULL);
}
}
} /* if (typepixel == VFF_TYP_DOUBLE) */

fclose(fd);

return image;
} /* readimage() */

struct xvimage *main(){
readimage("im1.pgm");
}

"mcutil.h"

/* $Id: mcutil.h,v 1.2 2009/01/07 12:46:34 mcouprie Exp $ */
#ifdef __cplusplus
extern "C" {
#endif

# define FLOAT_MAX 3.40282347e+38F

#define mcabs(X) ((X)>=0?(X):-(X))
#define max(X,Y) ((X)>=(Y)?(X):(Y))
#define min(X,Y) ((X)<=(Y)?(X):(Y))
#define odd(X) ((X)&1)
#define even(X) (((X)&1)==0)
#define arrondi(z) (((z)-(double)((int32_t)(z)))<=0.5?((int32_t)(z)):((int32_t)(z+1)))
#define signe(z) (((z)>0.0)?1.0:-1.0)
#define sqr(x) ((x)*(x))

#ifndef M_PI
# define M_E 2.7182818284590452354 /* e */
# define M_LOG2E 1.4426950408889634074 /* log_2 e */
# define M_LOG10E 0.43429448190325182765 /* log_10 e */
# define M_LN2 0.69314718055994530942 /* log_e 2 */
# define M_LN10 2.30258509299404568402 /* log_e 10 */
# define M_PI 3.14159265358979323846 /* pi */
# define M_PI_2 1.57079632679489661923 /* pi/2 */
# define M_PI_4 0.78539816339744830962 /* pi/4 */
# define M_1_PI 0.31830988618379067154 /* 1/pi */
# define M_2_PI 0.63661977236758134308 /* 2/pi */
# define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#endif
#ifdef __cplusplus
}
#endif

"mcimage.h"

/* $Id: mcimage.h,v 1.2 2009/01/07 12:46:33 mcouprie Exp $ */
#ifdef __cplusplus
extern "C" {
#endif
/* ============== */
/* prototypes for mcimage.c */
/* ============== */

extern struct xvimage *allocimage(char * name, int32_t rs, int32_t cs, int32_t d, int32_t t);
extern void razimage(struct xvimage *f);
extern struct xvimage *allocheader(char * name, int32_t rs, int32_t cs, int32_t d, int32_t t);
extern int32_t showheader(char * name);
extern void freeimage(struct xvimage *image);
extern struct xvimage *copyimage(struct xvimage *f);
extern int32_t copy2image(struct xvimage *dest, struct xvimage *source);
extern int32_t equalimages(struct xvimage *im1, struct xvimage *im2);
extern void list2image(struct xvimage * image, double *P, int32_t n);
extern double * image2list(struct xvimage * image, int32_t *n);

extern void writeimage(
struct xvimage * image,
char *filename
);

extern void writese(
struct xvimage * image,
char *filename,
int32_t x, int32_t y, int32_t z
);

extern void writelongimage(
struct xvimage * image,
char *filename
);

extern void writerawimage(
struct xvimage * image,
char *filename
);

extern void writeascimage(
struct xvimage * image,
char *filename
);

extern void printimage(
struct xvimage * image
);

extern void writergbimage(
struct xvimage * redimage,
struct xvimage * greenimage,
struct xvimage * blueimage,
char *filename
);

extern struct xvimage * readimage(
char *filename
);

extern struct xvimage * readheader(
char *filename
);

extern struct xvimage * readse(char *filename, int32_t *x, int32_t *y, int32_t*z);

extern struct xvimage * readlongimage(
char *filename
);

extern int32_t readrgbimage(
char *filename,
struct xvimage ** r,
struct xvimage ** g,
struct xvimage ** b
);

extern int32_t readbmp(
char *filename,
struct xvimage ** r,
struct xvimage ** g,
struct xvimage ** b
);

extern void writebmp(
struct xvimage * redimage,
struct xvimage * greenimage,
struct xvimage * blueimage,
char *filename
);

extern int32_t readrgb(
char *filename,
struct xvimage ** r,
struct xvimage ** g,
struct xvimage ** b
);

extern int32_t convertgen(struct xvimage **f1, struct xvimage **f2);
extern int32_t convertlong(struct xvimage **f1);
extern int32_t convertfloat(struct xvimage **f1);
#ifdef __cplusplus
}
#endif


"mccodimage.h"

/* $Id: mccodimage.h,v 1.5 2009/01/07 12:46:33 mcouprie Exp $ */
#ifdef __cplusplus
extern "C" {
#endif

#define NDG_MAX 255 /* niveau de gris max */
#define NDG_MIN 0 /* niveau de gris min */

/* definitions for data storage type,
uint32_t data_storage_type; */
#define VFF_TYP_BIT 0 /* pixels are on or off (binary image)*/
/* Note: This is an X11 XBitmap
with bits packed into a byte and
padded to a byte */
#define VFF_TYP_1_BYTE 1 /* pixels are byte (uint8_t) */
#define VFF_TYP_2_BYTE 2 /* pixels are two byte (int16_t) */
#define VFF_TYP_4_BYTE 4 /* pixels are four byte (integer) */
#define VFF_TYP_FLOAT 5 /* pixels are float (single precision)*/
#define VFF_TYP_DOUBLE 9 /* pixels are float (double precision)*/

struct xvimage {
char *name;
uint32_t row_size; /* Size of a row (number of columns) */
uint32_t col_size; /* Size of a column (number of rows) */
uint32_t depth_size; /* Number of planes (for 3d images) */
uint32_t time_size; /* Number of (2d or 3d) images */
uint32_t num_data_bands; /* Number of bands per data pixel,
or number of bands per image, or
dimension of vector data, or
number of elements in a vector */
uint32_t data_storage_type; /* storage type for disk data */
double xdim, ydim, zdim; /* voxel dimensions in real world */
uint32_t xmin, xmax; /* region of interest: x coordinates */
uint32_t ymin, ymax; /* region of interest: y coordinates */
uint32_t zmin, zmax; /* region of interest: z coordinates */
void * image_data; /* pointer on raw data */
};

#define UCHARDATA(I) ((uint8_t*)((I)->image_data))
#define USHORTDATA(I) ((uint16_t*)((I)->image_data))
#define ULONGDATA(I) ((uint32_t*)((I)->image_data))
#define FLOATDATA(I) ((float*)((I)->image_data))
#define DOUBLEDATA(I) ((double*)((I)->image_data))
#define colsize(I) ((I)->col_size)
#define rowsize(I) ((I)->row_size)
#define depth(I) ((I)->depth_size)
#define tsize(I) ((I)->time_size)
#define nbands(I) ((I)->num_data_bands)
#define datatype(I) ((I)->data_storage_type)
#define pixel(I,x,y) (((uint8_t*)((I)->image_data))[(y)*(I)->row_size+(x)])
#define voxel(I,x,y,z) (((uint8_t*)((I)->image_data))[((z)*(I)->col_size+(y))*(I)->row_size+(x)])
#define lpixel(I,x,y) (((uint32_t*)((I)->image_data))[(y)*(I)->row_size+(x)])
#define lvoxel(I,x,y,z) (((uint32_t*)((I)->image_data))[((z)*(I)->col_size+(y))*(I)->row_size+(x)])

/*
Codage du voisinage


3 2 1
4 X 0
5 6 7
*/
#define EST 0
#define NORD 2
#define OUEST 4
#define SUD 6
#define NORD_EST 1
#define NORD_OUEST 3
#define SUD_OUEST 5
#define SUD_EST 7
#define DEVANT 8
#define DERRIERE 10

#define nonbord(p,rs,N) ((p%rs!=rs-1)&&(p>=rs)&&(p%rs!=0)&&(p<N-rs))
#define nonbord3d(p,rs,ps,N) ((p>=ps)&&(p<N-ps)&&(p%ps>=rs)&&(p%ps<ps-rs)&&(p%rs!=0)&&(p%rs!=rs-1))

/* ============== */
/* prototypes */
/* ============== */

extern int32_t voisin(int32_t i, int32_t k, int32_t rs, int32_t nb);
extern int32_t voisin2(int32_t i, int32_t k, int32_t rs, int32_t nb);
extern int32_t voisin6(int32_t i, int32_t k, int32_t rs, int32_t n, int32_t nb);
extern int32_t bord(int32_t i, int32_t rs, int32_t nb);
extern int32_t bord3d(int32_t i, int32_t rs, int32_t ps, int32_t nb);
extern int32_t voisin26(int32_t i, int32_t k, int32_t rs, int32_t n, int32_t nb);
extern int32_t voisin18(int32_t i, int32_t k, int32_t rs, int32_t n, int32_t nb);
extern int32_t voisins4(int32_t i, int32_t j, int32_t rs);
extern int32_t voisins8(int32_t i, int32_t j, int32_t rs);
extern int32_t voisins6(int32_t i, int32_t j, int32_t rs, int32_t ps);
extern int32_t voisins18(int32_t i, int32_t j, int32_t rs, int32_t ps);
extern int32_t voisins26(int32_t i, int32_t j, int32_t rs, int32_t ps);
extern int32_t voisin5(int32_t i, int32_t k, int32_t rs, int32_t nb);
extern int32_t voisin6b(int32_t i, int32_t k, int32_t rs, int32_t nb, int32_t par);
extern int32_t voisinNESO(int32_t i, int32_t k, int32_t rs, int32_t nb);
extern int32_t voisinNOSE(int32_t i, int32_t k, int32_t rs, int32_t nb);
extern int32_t voisin14b(int32_t i, int32_t k, int32_t rs, int32_t ps, int32_t N);
extern int32_t voisinONAV(int32_t i, int32_t k, int32_t rs, int32_t ps, int32_t N );
extern int32_t voisinENAR(int32_t i, int32_t k, int32_t rs, int32_t ps, int32_t N );
extern int32_t voisinENAV(int32_t i, int32_t k, int32_t rs, int32_t ps, int32_t N );
extern int32_t voisinONAR(int32_t i, int32_t k, int32_t rs, int32_t ps, int32_t N );
extern uint32_t maskvois26(uint8_t *F, uint32_t bitmask, int32_t i, int32_t rs, int32_t ps, int32_t N);
#ifdef __cplusplus
}
#endif


"makefile"

#fonction readimage seul

install: all
mv -f open $(HOME)/bin


all: open

open: openimage.o mcutil.o mcimage.o mccodimage.o
gcc openimage.o mcutil.o mcimage.o mccodimage.o -o open

openimage.o : openimage.c mcutil.h mcimage.h mccodimage.h
gcc -wall openimage.c




Alors j'ai les erreurs suivantes:

gcc -wall openimage.c
gcc: unrecognized option '-wall'
openimage.c:7:21: erreur: mcimage.h : Aucun fichier ou dossier de ce type
openimage.c:8:24: erreur: mccodimage.h : Aucun fichier ou dossier de ce type
openimage.c:9:20: erreur: mcutil.h : Aucun fichier ou dossier de ce type
openimage.c: Dans la fonction «readimage» :
openimage.c:63: erreur: «VFF_TYP_1_BYTE» undeclared (first use in this function)
openimage.c:63: erreur: (Each undeclared identifier is reported only once
openimage.c:63: erreur: for each function it appears in.)
openimage.c:66: erreur: «VFF_TYP_4_BYTE» undeclared (first use in this function)
openimage.c:67: erreur: «VFF_TYP_FLOAT» undeclared (first use in this function)
openimage.c:70: erreur: «VFF_TYP_DOUBLE» undeclared (first use in this function)
openimage.c:119: attention : assignment makes pointer from integer without a cast
openimage.c:124: erreur: déréférencement d'un pointeur de type incomplet
openimage.c:125: erreur: déréférencement d'un pointeur de type incomplet
openimage.c:126: erreur: déréférencement d'un pointeur de type incomplet
openimage.c:136: erreur: la valeur indicée n'est ni un tableau ni un pointeur
openimage.c:142: erreur: la valeur indicée n'est ni un tableau ni un pointeur
openimage.c:152: attention : passing argument 1 of «fread» makes pointer from integer without a cast
openimage.c:167: erreur: la valeur indicée n'est ni un tableau ni un pointeur
openimage.c:172: attention : passing argument 1 of «fread» makes pointer from integer without a cast
openimage.c:187: erreur: la valeur indicée n'est ni un tableau ni un pointeur
openimage.c:192: attention : passing argument 1 of «fread» makes pointer from integer without a cast
openimage.c:207: erreur: la valeur indicée n'est ni un tableau ni un pointeur
openimage.c:212: attention : passing argument 1 of «fread» makes pointer from integer without a cast
openimage.c: Dans la fonction «main» :
openimage.c:226: attention : return type of «main» is not «int»
make: *** [openimage.o] Erreur 1


Aider moi SVP
merci d'avance

1 réponse

C'est pas compliqué, le compilateur te dit tout:

- openimage.c:7:21: erreur: mcimage.h : Aucun fichier ou dossier de ce type
- openimage.c:8:24: erreur: mccodimage.h : Aucun fichier ou dossier de ce type
- openimage.c:9:20: erreur: mcutil.h : Aucun fichier ou dossier de ce type
Il te dit qu'il trouve pas mcimage.h ... débrouille-toi pour qu'il les trouve; il faut les mettre dans le même répertoire et écrire:
#include "mcimage.h"
#include "mccodimage.h"
#include "mcutil.h"


- openimage.c: Dans la fonction «readimage» :
- openimage.c:63: erreur: «VFF_TYP_1_BYTE» undeclared (first use in this function)
Il te dit qu'il ne sait pas ce qu'est «VFF_TYP_1_BYTE», alors dit le lui.
Et ainsi de suite...
1