【发布时间】:2015-01-08 00:33:50
【问题描述】:
我正在尝试为项目设置 arm 调试环境。项目所需的主要代码功能之一是将二进制文件加载到内存(6mb)中。
我在 ubuntu linux 12.04 上安装了 qemu-arm,编译了 GDB,目标设置为 arm。我正在尝试编译以下测试代码:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdint.h>
int main()
{
int fd = open("files/test.txt", O_RDONLY);
printf("File handle: %i ", fd);
perror(NULL);
return 0
}
命令行:
arm-linux-gnueabihf-gcc -static -no-stack-protector -g test.c -o test;qemu-arm ./test
输出:
File handle: -1 No such file or directory
似乎找不到该文件,我相信这是因为 QEMU 无法访问它...我对 QEMU 不是很有经验,但鉴于我之前在虚拟机方面的经验,我猜这是就这样吧。
谁能帮忙解决这个问题?
编辑: 哇,我解决了,似乎我的代码中有错字,文件路径不正确。现在修复了...我应该关闭它吗?我的问题是无效的,因为它是一个愚蠢的错字。我发布的代码中没有错字。
【问题讨论】:
-
您不查询
errno并查看究竟是什么阻止了程序打开文件?只需在fd = open(...行之后写perror(NULL);。 -
稍后将尝试编辑。我的 c 代码很弱,我不知道该怎么做。