Bonjour , je suis en train de faire un programme de gestion de processus.Cependant j'ai un petit problème avec l'inclusion de variables globales situées dans un fichier .h .Pour y remédier j'ai essayé avec le mot clé "extern" mais le problème persiste . Pourriez-vous donc m'éclairer svp?
les erreurs en question:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
gcc tp3_main.o tp3_aff.o -o tp3_main
tp3_aff.o: In function `verifaff':
tp3_aff.c:(.text+0x7): undefined reference to `str1'
tp3_aff.c:(.text+0x1c): undefined reference to `str2'
tp3_aff.c:(.text+0x31): undefined reference to `str3'
tp3_aff.c:(.text+0x46): undefined reference to `str4'
tp3_aff.c:(.text+0x5b): undefined reference to `str5'
tp3_aff.c:(.text+0x70): undefined reference to `str6'
tp3_aff.c:(.text+0x85): undefined reference to `str7'
tp3_aff.c:(.text+0x9a): undefined reference to `str8'
le fichier auxquelles elles font réferences :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//str.h
#ifndef STR_H
#define STR_H
 
extern char *str1;
extern char *str2;
extern char *str3;
extern char *str4;
extern char *str5;
extern char *str6;
extern char *str7;
extern char *str8;
 
#endif
le fichier main.c(je n'ai mis que le code qui intervient dans l'erreur)
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
 
//main.c
#include"tp3_str.h"
#include"tp3_aff.h"
#include <stdlib.h>
#include <stdio.h>
 
 
int main(int argc,char *argv[])
{
	char *str1=" _____                                                              |";
	char *str2="|  __ \\                                                             |";
	char *str3="| |__) |  _ __    ___     ___    ___   ___   ___   _   _   ___      |";
	char *str4="|  ___/  |  __|  / _ \\   / __|  / _ \\ / __| / __| | | | | / __|     |";
	char *str5="| |      | |    | (_) | | (__  |  __/ \\__ \\ \\__ \\ | |_| | \\__ \\     |";
	char *str6="| |      | |    | (_) | | (__  |  __/ \\__ \\ \\__ \\ | |_| | \\__ \\     |";
	char *str7="|_|      |_|     \\___/   \\___|  \\___| |___/ |___/  \\__,_| |___/     |";
	char *str8="                                                                    |";
}
et enfin l'autre fichier de fonctions:
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
//aff.c
#include"tp3_str.h"
#include"tp3_aff.h"
 
 
void verifaff()
{
	printf("%s \n",str1);
	printf("%s \n",str2);
	printf("%s \n",str3);
	printf("%s \n",str4);
	printf("%s \n",str5);
	printf("%s \n",str6);
	printf("%s \n",str7);
	printf("%s \n",str8);
}
 
void affprocess1()
{
	printf(" %s ",str1);
	/*//printf("Père: %d ,Fils: %d [0]\n",getpid());*/
	printf("%s \n",str2);
	printf("%s \n",str3);
	printf("%s \n",str4);
	printf("%s \n",str5);
	printf("%s \n",str6);
	printf("%s \n",str7);
	printf("%s \n",str8);
}
void affprocessn()
{
	printf(" %s ",str1);
	/*printf("Père: %d ,Fils: %d [0]\n",getpid(),fork());*/
	printf("%s \n",str2);
	printf("%s \n",str3);
	printf("%s \n",str4);
	printf("%s \n",str5);
	printf("%s \n",str6);
	printf("%s \n",str7);
	printf("%s \n",str8);
}
voila , votre aide me serait d'un grand secours car après avoir essayé différentes méthodes ces erreurs d'inclusions et de définitions persistent.
En vous remerciant d'avance.