我从讲师那里得到了一些示例代码,这些代码用于递归列出FAT12磁盘映像文件中的所有文件和目录。
我仔细按照说明进行操作,但收到一些奇怪的错误消息,如下所示:
ld: warning: ignoring file floppy.img, file was built for unsupported file format
(0xEB 0x3C 0x90 0x42 0x53 0x44 0x20 0x20 0x34 0x2E 0x34 0x00 0x02 0x01 0x01 0x00 )
which is not the architecture being linked (x86_64): floppy.img
Undefined symbols for architecture x86_64:
"_check_bootsector", referenced from:
_main in dos_ls-LKA1e2.o
"_cluster_to_addr", referenced from:
_follow_dir in dos_ls-LKA1e2.o
"_get_fat_entry", referenced from:
_ follow_dir in dos_ls-LKA1e2.o
"_mmap_file", referenced from:
_main in dos_ls-LKA1e2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gcc ./dos_ls.c floppy.img是我在终端中使用的命令。dos_ls.c是c文件,floppy.img是他提供给我们的示例img。
我相信这张img的格式有问题吗?
谁能解释这个错误,然后告诉我如何解决?
更新:例如,“ ./ dos_ls floppy.img”将列出磁盘映像文件floppy.img中的所有文件和目录。这是我的指示。我的工作有什么问题吗?
gcc ./dos_ls.c给出此错误消息:
Undefined symbols for architecture x86_64:
"_check_bootsector", referenced from:
_main in dos_ls-xHY6F1.o
"_cluster_to_addr", referenced from:
_follow_dir in dos_ls-xHY6F1.o
"_get_fat_entry", referenced from:
_follow_dir in dos_ls-xHY6F1.o
"_mmap_file", referenced from:
_main in dos_ls-xHY6F1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-
include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
更新:gcc -o hello dos_ls.c dos.c在当前目录中创建一个新文件:
Usage: dos_ls <imagename>
logout
[Process completed]
执行此操作的正确方法是什么?
根据您添加到问题中的信息,您的问题是该dos_ls.c
文件调用了一些此处未定义的函数。
因此,链接器抱怨找不到这些函数的实现,因此未定义符号。
如果您的讲师为您提供了更多的.c源文件,其中包含这些函数的定义(以及提供功能声明的关联头文件),则必须将它们与主源文件一起编译。
我假设与fat12相关的功能,所以我在想您有以下文件:
dos_ls.c
fat12.h
fat12.c
通常,dos_ls.c将#include "fat12.h"
,并且您需要使用如下命令行来编译.c文件:
gcc -o dos_ls dos_ls.c fat12.c
这应该工作。
现在,要使用提供的图像文件作为参数执行二进制文件,只需键入:
./dos_ls floppy.img
这正是您在问题中引用的说明。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句