【问题标题】:32-bit nasm assembly not starting on 64 bit system32 位 nasm 程序集未在 64 位系统上启动
【发布时间】:2012-05-23 09:22:13
【问题描述】:

我编写了一个 32 位汇编文件,我想在 64 位 Linux 系统上编译它(并让它工作)。我已经安装了gcc-multiliblib32-glibc

我尝试使用以下命令创建二进制文件:

nasm -f elf test.asm
ld -melf_i386 -o test -e _main test.o /usr/lib32/libc.so.6 

_main 是入口点。文件 test 已创建,我对其进行 chmod:

chmod ugo+x ./test

但是,我无法打开它。我明白了:

bash: ./test: No such file or directory

我确定该文件存在,因为我可以在 vim 中打开它(并且我可以看到第一行写有 ELF)。这是怎么回事?

【问题讨论】:

    标签: 32bit-64bit nasm ld


    【解决方案1】:

    该消息与动态链接器有关,因为使用动态库需要更多的努力。简单的方法是链接到静态 C 库 (/usr/lib32/libc.a)。但是,如果您只是将入口点称为“main”并像普通 C 程序(gcc -m32 -o test test.o)一样链接它,它也可以工作。

    【讨论】:

      【解决方案2】:

      问题不在编译器中。

      其实你输入了一个错误的命令。

      1)编译32位程序的命令是:nasm -f elf32 test.asm

          and for 64 bit asm or assembly language file command is : nasm -f elf64 test.asm
      

      2) 编译后,您需要为该命令链接该文件:

           ld -o test test.o  ( for both the 64/32 bit program)
      

      3) 现在你可以使用命令来执行程序了:

            ./test
      

      【讨论】:

        猜你喜欢
        • 2023-03-20
        • 1970-01-01
        • 2019-07-06
        • 1970-01-01
        • 2011-07-07
        • 2015-09-26
        • 2018-11-14
        相关资源
        最近更新 更多