嵌入式爱好者

查看: 2459|回复: 2

[Linux] 请教如何编译和执行二进制文件

[复制链接]

1

主题

2

帖子

11

积分

A40i/T3/T507/T527通行证

扫一扫,手机访问本帖
发表于 2022-9-27 11:25:22 | 显示全部楼层 |阅读模式
本帖最后由 heima21 于 2022-9-27 12:19 编辑

我简单编写了个helloworld,执行时提提示cannot execute binary file: Exec format error,请教下是哪里配置问题?ubuntu版本 18 64位,a40i的OKA40i-C开发板
uname -a
Linux forlinx 5.4.0-70-generic #78~18.04.1-Ubuntu SMP Sat Mar 20 14:10:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
由于不能发图,所以粘贴了代码,请技术支持帮忙分析下,谢谢
test.c
int main(int argc, char **argv)
{
    printf("hello world\n");
}


makefile
TARGET         =test
DEST_DIR      ?=_install
CC            ?=arm-linux-gcc

build:
  @$(CC) -o $(TARGET) test.c -lpthread

hold:
  @echo "test hold[skip]"

install:
  @mkdir -p $(DEST_DIR)
  @cp $(TARGET) $(DEST_DIR)

uninstall:
  @rm -fr $(DEST_DIR)/$(TARGET)

distclean: uninstall
  @rm -fr $(TARGET)
  @rm -fr _install

以下是a40开发板超级终端执行情况
# tftp -g -r a40i/v101/test 192.168.0.8 && chmod 777 test
# ls -l
total 4536
-rwxr-xr-x    1 root     root           648 Nov 30  2021 script_parser.sh
-rwxrwxrwx    1 root     root          8392 Sep 27 11:21 test
-rw-r--r--    1 root     root       2859895 Nov 30  2021 translate.mp4
-rw-r--r--    1 root     root       1764044 Nov 30  2021 wo.wav
# test
#
# ./test
-sh: ./test: cannot execute binary file: Exec format error
# uname -a
Linux A40i 3.10.65 #4 SMP PREEMPT Thu Mar 17 01:45:52 UTC 2022 armv7l GNU/Linux
#






回复

使用道具 举报

1

主题

2

帖子

11

积分

A40i/T3/T507/T527通行证

 楼主| 发表于 2022-9-27 12:16:03 | 显示全部楼层
本帖最后由 heima21 于 2022-9-27 12:22 编辑

怎么上传的图片都不显示?
不知道是不是因为64位ubuntu编译的程序在arm上不能运行的问题?请教下,如何在64位ubuntu上编译可以在arm linux上运行的程序?谢谢
点评回复 支持 反对

使用道具 举报

0

主题

9

帖子

321

积分

发表于 2022-9-28 09:00:28 | 显示全部楼层
Ubuntu中需要使用对应的交叉工具编译链编译的程序才能够在arm开发板里面使用,如果使用的是飞凌官网A40i平台上下载的的Ubuntu18.04的开发环境,交叉编译器的路径应该是:/opt/arm/opt/ext-toolchain/bin/arm-linux-gnueabihf-gcc,按照用户编译手册上的4.3章节,单独编译应用程序操作,在Makefile指定编译器CC =arm-linux-gnueabihf-gcc-5.3.1,然后加载环境变量,然后再编译
点评回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2025-2-6 05:58

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表