Threads mit Posix und KDevelop
-
Ich versuche grade mit posix unter c++ im KDevelop threading zu programmieren aber leider hauts nicht ganz hin. Mein Programm lässt sich zwar erfolgreich kompilieren aber beim ausführen krieg ich dann folgende Fehlermeldung.
cpp:34: undefined reference to `pthread_create'
mein Code schaut so aus :
#include <pthread.h> #include <stdio.h> #include <stdlib.h> #define NUM_THREADS 5 void *PrintHello(void *threadid) { printf("\n%d: Hello World!\n", threadid); pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc, t; for(t=0;t<NUM_THREADS;t++){ printf("Creating thread %d\n", t); rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); if (rc){ printf("ERROR; return code from pthread_create() is %d\n", rc); exit(0); } } pthread_exit(NULL); } Compilieren geht wie gesagt einwandfrei. Irgendwie siehts so aus als wenn der Kdevelop die Lib nicht finden würde! Weiss jemand abhilfe ?
-
project -> options -> linker options -> additional libraries: -lpthread
-
Danke es funktioniert !