Я пытаюсь скомпилировать простую программу на C с Pthreads в Ubuntu с помощью codelite.
Я выбрал GCC в качестве своего компилятора и добавил "-pthread" в параметры компилятора C в настройках проекта. Но во время компиляции выдает ошибку "undefined reference to pthread_create"
.
Если я вызываю GCC через командную строку вручную, он собирается и запускается.
Но когда я комментирую оскорбительную строку, она компилируется без ошибок в codelite.
Поэтому я подозреваю, что codelite не добавляет флаг компилятора -pthread при компиляции.
Любая помощь приветствуется.
Вот выдержка из моего кода:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
//function prototypes
void * monitor_thread (void* data);
int main(int argc, char *argv[])
{
// exit program if no arguments are supplied
if(argc < 3)
{
printf("Not enough arguments passed \n");
return 0;
}
// parse arguments
int arrivalProbability = atoi(argv[1]);
int departureProbability = atoi(argv[2]);
// exit the program in entered values are not valid
if (arrivalProbability >=90 || departureProbability >=90)
{
printf("Argument(s) exceed a probability of 90%% \n");
return 0;
}
else if (arrivalProbability == 0 || departureProbability == 0)
{
printf("Argument(s)entered are zero or not intergers \n");
return 0;
}
// create the threads
int thr_id; /* thread ID for the newly created thread */
pthread_t p_thread; /* thread's structure */
int monitor = 1; /* monitor thread identifying number */
int arrival = 2; /* arrival thread identifying number */
int departure = 3; /* departure thread identifying number */
// monitor thead
// "undefined reference to pthread_create"
thr_id = pthread_create(&p_thread, NULL, monitor_thread, (void*)&monitor);
return 0;
}
void * monitor_thread (void* data)
{
int monitorThreadID = *((int*)data); /* thread identifying number */
printf("monitor thread");
sleep(1);
}