【问题标题】:Assembly code compilation error: file not recognized汇编代码编译错误:文件无法识别
【发布时间】:2013-07-01 19:52:06
【问题描述】:

我正在尝试编译汇编代码。

我使用了命令

nasm -f coff myMergeSort.asm
gcc driver.c myMergeSort.o asm_io.o -o merge

但我收到以下错误:

myMergeSort.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

我尝试使用“obj”代替“coff”,但它给出了类似的错误。

使用“elf”代替“coff”会出现以下错误:

myMergeSort.o: In function `main':
myMergeSort.asm:(.text+0x0): multiple definition of `main'
/tmp/cchbsJLl.o:driver.c:(.text+0x0): first defined here
/tmp/cchbsJLl.o: In function `main':
driver.c:(.text+0xa): undefined reference to `asm_main'
collect2: error: ld returned 1 exit status

我该如何解决?

【问题讨论】:

  • @Michael:是的,我尝试使用 elf,它给出了错误“main 的多重定义”,就像我在问题中发布的那样
  • 谁的代码是driver.c?看起来它希望您的汇编代码导出一个名为 asm_main 而不是 main 的函数。

标签: gcc assembly cross-compiling nasm


【解决方案1】:

在 driver.c 中你可能调用了 asm_main,尝试添加 extern return_type asm_main(Type1 name1, ..., Typen namen);

return_type 被函数的返回类型替换,typei 是 TYPE 我传递的参数编号。

【讨论】:

    猜你喜欢
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 2019-12-10
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 2014-08-08
    相关资源
    最近更新 更多