主题 : tiny210开发板执行可执行文件问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 95789
精华: 0
发帖: 25
金钱: 130 两
威望: 26 点
综合积分: 50 分
注册时间: 2013-08-24
最后登录: 2014-01-02
楼主  发表于: 2013-10-17 17:10

 tiny210开发板执行可执行文件问题

图片:
图片:
我的tiny210装的是android4.0.3,我按照用户手册用超级终端执行led的时候出现了这个问题,请问如何解决呢?

后面我用arm-linux-gcc 编出来的led.exe也是这个问题。

我是按照用户手册给的源程序弄的

*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2013-10-18 12:17

 回 楼主(545140591) 的帖子

你截图上的这个LED源代码看起来应该是裸机程序,不能在Android环境下运行。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 95789
精华: 0
发帖: 25
金钱: 130 两
威望: 26 点
综合积分: 50 分
注册时间: 2013-08-24
最后登录: 2014-01-02
2楼  发表于: 2013-10-18 14:34

 回 1楼(kasim) 的帖子

不是裸机程序,是光盘里面的资料,源码如led.c下:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char **argv)
{
    int on;
    int led_no;
    int fd;

    if (argc != 3 || sscanf(argv[1], "%d", &led_no) != 1 || sscanf(argv[2],"%d", &on) != 1 ||
            on < 0 || on > 1 || led_no < 0 || led_no > 3) {
        fprintf(stderr, "Usage: leds led_no 0|1\n");
        exit(1);
    }

    fd = open("/dev/leds", 0);
//    if (fd < 0) {
//        fd = open("/dev/leds", 0);
//    }
//    if (fd < 0) {
//        perror("open device leds");
//        exit(1);
//    }

    ioctl(fd, on, led_no);
    close(fd);

    return 0;
}


Makefile的源码:
# ----------------------------------------------------------------------------
# Makefile for building tapp
#
# Copyright 2010 FriendlyARM (http://www.arm9.net/)
#

ifndef DESTDIR
DESTDIR               ?= /tmp/FriendlyARM/mini6410/rootfs
endif

CFLAGS                = -Wall -O2
CC                    = arm-linux-gcc
INSTALL                = install

TARGET                = led


all: $(TARGET)

led: led.c
    $(CC) $(CFLAGS) $< -o $@


install: $(TARGET)
    $(INSTALL) $^ $(DESTDIR)/usr/bin

clean distclean:
    rm -rf *.o $(TARGET)


# ----------------------------------------------------------------------------

.PHONY: $(PHONY) install clean distclean

# End of file
# vim: syntax=make


我make之后得到的led可执行文件放到开发板不能用./led执行,报错就如/system/bin/sh:./led not found

谢谢版主热心回答
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2013-10-18 15:26

 回 2楼(545140591) 的帖子

从源代码看,这个程序依赖于glibc库,只能跑在Linux环境下。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 95789
精华: 0
发帖: 25
金钱: 130 两
威望: 26 点
综合积分: 50 分
注册时间: 2013-08-24
最后登录: 2014-01-02
4楼  发表于: 2013-10-18 15:41

 回 3楼(kasim) 的帖子

原来如此!谢版主了。那有适合android系统的制作可执行文件调用open之类的函数吗?因为通过jni调用的话麻烦了一点
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
5楼  发表于: 2013-10-18 17:58

 回 4楼(545140591) 的帖子

像open这样的系统调用在Android上也是适用的。事实上,最简单的办法就是把这个程序用静态编译(在gcc的命令行上加上--static参数)应该就可以跑在Android上了。
对于Android上运行的Native C程序,我想你可以参考源代码目录system/core/charger/下的写法。当然,你也可以通过Android NDK(http://developer.android.com/tools/sdk/ndk/index.html)来写
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 95789
精华: 0
发帖: 25
金钱: 130 两
威望: 26 点
综合积分: 50 分
注册时间: 2013-08-24
最后登录: 2014-01-02
6楼  发表于: 2013-10-19 15:37

 回 5楼(kasim) 的帖子

原来是静动态库问题,现在搞懂了,非常感谢版主的帮助!