mercredi 11 mars 2015

arm-none-eabi-g++ compiler throws compilation error pthread_exit was not declared in this scope

Running in debian linux "arm-none-eabi-g++ pthread.c -o pthread -lpthread" throws below compilation error. But if I run the "g++ pthread.c -o pthread -lpthread " there is no compilation errors. I never used cross compiler. I knew there is problem in linking in libraries. Please help me. I searched lot in the internet but there is no luck.


My pthread.c program



include "pthread.h"
include "stdio.h"
include "stdlib.h"

void *worker_thread(void *arg) {
printf("This is worker_thread()\n");
pthread_exit(NULL);
}

int main() {
pthread_t my_thread;
int ret;
printf("In main: creating thread\n");
ret = pthread_create(&my_thread, NULL, &worker_thread, NULL);
if(ret != 0) {
printf("Error: pthread_create() failed\n");
exit(EXIT_FAILURE);
} pthread_exit(NULL);
}


Compilation error:



pthread.c: In function 'void* worker_thread(void*)':

pthread.c:8:18: error: 'pthread_exit' was not declared in this scope
pthread_exit(NULL);
^
pthread.c: In function 'int main()':
pthread.c:15:1: error: 'pthread_t' was not declared in this scope
pthread_t my_thread;
^
pthread.c:15:11: error: expected ';' before 'my_thread'
pthread_t my_thread;
^
pthread.c:18:23: error: 'my_thread' was not declared in this scope
ret = pthread_create(&my_thread, NULL, &worker_thread, NULL);
^
pthread.c:18:60: error: 'pthread_create' was not declared in this scope
ret = pthread_create(&my_thread, NULL, &worker_thread, NULL);
^
pthread.c:24:21: error: 'pthread_exit' was not declared in this scope
} pthread_exit(NULL);

Aucun commentaire:

Enregistrer un commentaire