您的位置:首页 > 编程语言 > Java开发

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

2014-04-14 20:29 387 查看
作者:ex_net

转自:/article/1405596.html

第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++的跨平台编程是不是很简单呢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: