繁体   English   中英

在Ubuntu上的Eclipse IDE上的Yocto插件上对`pthread_create'的未定义引用

[英]undefined reference to `pthread_create' on Yocto plugin on Eclipse IDE on Ubuntu

我正在Eclipse IDE中针对使用Yocto制作的元工具链(用于手臂皮质A9处理器)进行交叉编译测试。 在成功执行了hello world测试之后,我创建了一个测试pthread的基本程序。

    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <fcntl.h>
    #include <time.h>
    #include <pthread.h>

    #define MILLION 1000000         /* one million = 10^6*/
    #define sec_to_nsec 1000000000  /* ns to s conversion = 10^9 */
    #define FILENAME "Schd.txt"
    #define FLUSH_TIME 10.0
    #define SIG_LLP_TIMER       SIGRTMIN+1

    int     isr_idx;            /* counter of ISR occurred -- starts from 0 and increments at each interrupt*/

    volatile float  clk_k,              /* MY_CLOCK() value for the current sample*/
            clk_k_1;            /* MY_CLOCK() value for the previous sample*/

    /*clock and timer values*/
    struct itimerspec custom_itimerspec;
    timer_t timer_id;
    clockid_t USED_CLK;
    struct  timespec tv;

    float a_n;

    /*THREAD DATA*/
    pthread_t thread0;
    pthread_attr_t attr;
    struct sched_param param;
    using namespace std;



    void* thread_scheduler(){
        //function pointer
        //mainThread
        //make thread for scheduling
        //exit after max cycle
    }

    int main(void) 
    {

            cout << "Starting the program!" << endl; /* prints Hello World */

            cout<< "Creating a Thread to deploy" << endl;


            int  status;


            param.__sched_priority = 99;


                int retc;
                /*PTHREAD ATTR setup*/
                retc = pthread_attr_init(&attr);
                retc |= pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
                retc |= pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
                retc |= pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
                retc |= pthread_attr_setschedparam(&attr,&param);


                if (retc != 0) {
                    //fail
                    while(1){}
                }


                retc = pthread_create(&thread0, &attr, (void * (*)(void *))thread_scheduler, NULL);

            printf("Exiting here!");
            return 0;





    }

但是我得到这个错误,未定义的对“ pthread_create”的引用,以及一些make错误。

虽然做了一些搜索,我发现,在配置和AUTOGEN设置中添加“-pthread”命令工程建设项目,如描述后这里 但是,令我困惑的是,为什么即使项目浏览器的下拉文件夹中的“ includes”中包含此文件,编译器也看不到这些文件。

关于未定义引用的错误来自链接步骤,而不是来自编译和组装步骤,编译步骤将查找头文件,并正确地从sysroot include目录中找到pthread.h ,如您所见。 编译后,它必须调用链接器来创建可执行二进制文件,这就是失败的地方。

链接时,需要将libpthread添加到链接器命令行中,以便链接器可以找到pthread_create函数并将其链接到最终可执行文件中,这通常是通过指定LDFLAGS来完成的,然后将其附加到链接器调用中。

编译器驱动程序(gcc)可用于驱动编译和链接步骤。 因此,当您将-pthread选项添加到编译器并且编译器也用于执行链接时,它将把该选项转换为-lpthread到链接器cmdline,后者随后将找到libpthread并将其链接到其中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM