Strona 1 z 1

[SOLVED] [C]Nie tworzy wątków (pthread_create undefined reference)

: 21 lip 2009, 13:15
autor: trucha
Przejrzałem temat viewtopic.php?t=95389 i nie bardzo rozumiem odpowiedź.

Problem polega na tym:

Kod: Zaznacz cały

zad.c:(.text+0x825): undefined reference to 'pthread_create'
collect2: ld returned 1 exit status
kod main:

Kod: Zaznacz cały

int main()
{
pthread_t g1, g2,pac;
time_t start,end;
clock_t start2,end2;
double dif2;
int i,il,k,k2,l,p1=70,p2=80,p3=90;

pthread_mutex_init(&mut[0],NULL);
pthread_mutex_init(&mut[1],NULL);
pthread_mutex_init(&mut[2],NULL);
pthread_create(&g1, NULL, &gabinet1, NULL);       TUTAJ 
pthread_create(&g2, NULL, &gabinet2, NULL);        JEST
pthread_create(&pac, NULL, &pacjenci, NULL);        BLAD
srand(time(0));
time (&start);
while(dif<dlp)
{
 time (&end); 
 dif = difftime (end,start);
}
printf("Koniec czasu przyjec  pacjentow\n");
while(g1z!=0||g2z!=0||dl_kol1!=-1||dl_kol2!=-1);
printf("Koniec pracy przychodni\n");
return 0;
}

Odp: Nie tworzy wątków (pthread_create)

: 21 lip 2009, 13:45
autor: Hauleth
po 1 nie dołączyłeś pthread.h, po 2 jak nie wiesz co to linker to po co się pchasz do wątków??

Odp: [C]Nie tworzy wątków (pthread_create undefined reference)

: 21 lip 2009, 13:52
autor: trucha
Po pierwsze mam dołączone pthread.h a po drugie chyba nie musze rozumiec wszystkich pojec prawda? Wydaje mi sie, ze forum jest po to aby tlumaczyc cos sobie na wzajem, a nie tak jak Ty od razu negowac....

Odp: [C]Nie tworzy wątków (pthread_create undefined reference)

: 21 lip 2009, 14:30
autor: Macok
Spróbuj przy kompilacji dodać -pthread, czyli jak kompilowałeś

Kod: Zaznacz cały

gcc main.cpp
to sprobuj

Kod: Zaznacz cały

gcc main.cpp -pthread
haulethem sie nie przejmuj bo to nie ma sensu.

Odp: [C]Nie tworzy wątków (pthread_create undefined reference)

: 21 lip 2009, 14:33
autor: trucha
Dzięki serdeczne za pomoc Macok ;-)
Wszystko już działa :-)