在Ubuntu下用Eclipse开发ARM多线程程序

第1步:安装 Eclipse 开发环境

      http://blog.csdn.net/ex_net/article/details/7251664

第2步:配置Eclipse 的arm开发环境

   http://blog.csdn.net/ex_net/article/details/7251845


第3步:新建一个过程,配置好环境

   敲入下面的代码

#include <pthread.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>

void *create(void *arg)
{
    while(1)
    {
    printf("thread is Running ..... ");
    sleep(5);
    }
}

void *ReaderThread(void *arg)
{
    while(1)
    {
            sleep(4);
            printf("Read ID=\r\n");
    }
}

int main(int argc, char *argv[])
{
    pthread_t tidp;
    int rc1,rc2;
     rc1=pthread_create(&tidp,NULL,create,NULL);
     if(rc1!=0)
     {
            printf("pthread_create is not created ... \r\n");
            return -1;
     }

     printf("prthread_create is created... \r\n");
     rc2=pthread_create(&tidp,NULL,ReaderThread,NULL);
     if(rc2!=0)
     {
            printf("ReaderThread is not created ... \r\n");
            return -1;
     }

     printf("ReaderThread is created... \r\n");
     while(1)
     {
         printf("System is Runing...\r\n");
         sleep(1);
     }
    return 0;
}

编译看看效果。



系统编译出错!

提示:undefined reference to `pthread_create'


原因是arm-linux-g++ 在默认编译情况下,不会加载线程库。

因此需要设置Eclipse

注意: 需要设置  ARM 和 Debug(X86)环境。



设置好后,再次编译看看


编译成功,没有错误!


下载到开发板,运行看看效果!



切换编译模式为DEBUG(x86)看看效果



左边是6410开发板上的程序效果,右边是X86的PC上效果!

酷吧!


C/C++的跨平台编程是不是很简单呢!


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值