voilà mes programmes commencent à être composés de plusieurs fonctions et structures. Je souhaiterai séparer le code sur plusieurs fichiers:
main.c
functions.c
structures.c
Ainsi ce sera mieux organisé.
J'ai essayé de faire ça mais ça me sort pleins d'erreurs.
Pourtant je n'ai fait que déplacer le code dans un autre fichier.
- Code: Tout sélectionner
$ gcc main.c -lSDLmain -lSDL
In file included from main.c:8:
functions.c:7: error: erreur de syntaxe before '*' token
functions.c: Dans la fonction « InitSprite »:
functions.c:10: error: `sprite' undeclared (first use in this function)
functions.c:10: error: (Each undeclared identifier is reported only once
functions.c:10: error: for each function it appears in.)
functions.c:10: error: `picture' undeclared (first use in this function)
functions.c:35: error: `DOWN' undeclared (first use in this function)
functions.c: Hors de toute fonction :
functions.c:54: error: erreur de syntaxe before '*' token
functions.c: Dans la fonction « InitBackground »:
functions.c:57: error: `background' undeclared (first use in this function)
functions.c:57: error: `picture' undeclared (first use in this function)
functions.c: Hors de toute fonction :
functions.c:76: error: erreur de syntaxe before '*' token
functions.c: Dans la fonction « UpdateSprite »:
functions.c:78: error: `sprite' undeclared (first use in this function)
functions.c:82: error: `UP' undeclared (first use in this function)
functions.c:85: error: `DOWN' undeclared (first use in this function)
functions.c:88: error: `RIGHT' undeclared (first use in this function)
functions.c:91: error: `LEFT' undeclared (first use in this function)
functions.c: Hors de toute fonction :
functions.c:112: error: erreur de syntaxe before '*' token
functions.c: Dans la fonction « UpdateBackground »:
functions.c:114: error: `sprite' undeclared (first use in this function)
functions.c:114: error: `video_width' undeclared (first use in this function)
functions.c:115: error: `background' undeclared (first use in this function)
functions.c:123: error: `video_height' undeclared (first use in this function)
main.c fait appel aux 2 autres fichiers:
- Code: Tout sélectionner
#include "functions.c"
#include "structures.c"
Pourquoi ça ne fonctionne pas?
Faut-il une fonction main( ) dans chaque fichier?
Merci