Уважаемые пользователи форума, при написании простой программы с нитями с использованием компилятора Gcc столкнулся с такой проблемой:
Вот лог
comp-217-1:/home/student# gcc Kripachev.c -o gg
/tmp/cc2cDQsr.o: In function `main':
Kripachev.c:(.text+0x30): undefined reference to `pthread_create'
Kripachev.c:(.text+0x53): undefined reference to `pthread_create'
Kripachev.c:(.text+0x66): undefined reference to `pthread_join'
Kripachev.c:(.text+0x79): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
А вот исходный код:
#include <stdio.h>
#include <pthread.h>
#define NUM 5
int main()
{
pthread_t t1,t2;
void *print_msg(void *);
pthread_create(&t1,NULL,print_msg,(void *)«hello»);
pthread_create(&t2,NULL, print_msg, (void *)«world\n»);
pthread_join(t1,NULL);
pthread_join(t2,NULL);
}
void *print_msg(void *m)
{
char *cp = (char *) m;
int i;
for(i = 0; i < NUM; i++){
printf(«%s», m);
fflush(stdout);
sleep(1);
}
return NULL;
}