Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

embedded - unresolved symbol pthread_create, first referenced in ./armrtk/src/task.obj

I have been trying to figure this out for a few days now and cannot figure it out. I am using CCS as the IDE and I am working on windows. I am trying to create an RTOS Kernel on a MSP432 and need to use pthreads. I have been able to use pthreads in other examples but I am trying to do my own program and I get this issue when building :

unresolved symbol pthread_create, first referenced in ./armrtk/src/task.obj

I have included the file path into CCS and I cannot use a .cfg file because I am not using XDCTools. I just need help with this and I greatly appreciate it. I also get a warning:

in pthread_create in TASK.C: #169-D argument of type "void *" is incompatible with parameter of type "void *(*)(void *)"

TASK.H

#ifndef TASK_H
#define TASK_H

#include <pthread.h>


struct task_t {
pthread_t* thread;
int threadCheck;
int state;
};

void *task1(void);
void *task2(void);

struct task_t *create_task(void* functionptr);

void delete_task(void *task);

 #endif

TASK.C

 #include <task.h>
 #include <stdlib.h>
 #include <pthread.h>

 #define BLOCKED -1
 #define READY 0
 #define RUNNING 1

 int testValue1 = 0;
 int testValue2 = 0;
 struct task_t *new_task;
 pthread_t pntr;

 struct task_t *create_task(void* functionptr) {

     new_task = malloc(sizeof(struct task_t));

     if(!new_task)
        return NULL;

    //set State of the new thread to ready
    new_task->state = 0;
    // check to see if pthread is created
    **new_task->threadCheck = pthread_create(new_task->thread, NULL, functionptr, NULL);**

    if(new_task->threadCheck!= 0){
        //thread failed
        return NULL;
    }

    return new_task;

    }

    void delete_task(void *task) {
        if(task != NULL){
            free(task);
            pthread_exit(NULL);
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The unresolved symbol error is a linker error, not a compiler error. You have failed to link the pthreads library.

With respect to the warning functionptr is a void* where pthread_create() expects a pointer-to-function with signature void fn(void*).

Your task functions have a different signature in any case: void fn(void), so in any event you will need to cast the function pointer in the call to pthread_create() (although you are loosing a useful means of passing information into a task function by omiting the void* argument).

Modify task.h:

typedef void* (*task_t)(void);
struct task_t *create_task( task_t functionptr);

The in task.cpp

new_task->threadCheck = pthread_create( new_task->thread, 
                                        NULL, 
                                        (void (*)(void *))functionptr, 
                                        NULL ) ;

The cast in the pthread_create() call alone would supress the warning, but it bad form to pass a function pointer as a generic void* since it would prevent the compiler warning you if you were to pass anything other then a function pointer of the expected form to to the create_task()`


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...