64-bit Ubuntu system using assembler NASM and C language

Source: Internet
Author: User

$ nasm-f elf Foo.asm-o foo.o
$ gcc-c Bar.c-o BAR.O
$ ld-s foo.o Bar.o-o Foobar

  ld:i386 Architecture of input file ' foo.o ' is incompatible with i386:x86-64 output

This means that the NASM compiler produces a 32-bit target code, and GCC produces a 64-bit target code by default on a 64-bit platform.

These two errors are linked, and GCC is linked by default to 64-bit on 64-bit platforms.

-------------------------------------------------------------------------------------------------------

Method:

Let GCC generate 32-bit code and link it in 32-bit way

In this case, you only need to modify the compile and link instructions, as follows:

32-bit compiled link directives

$ nasm-f elf Foo.asm-o foo.o

$ gcc-m32-c Bar.c-o BAR.O

$ ld-m elf_i386-s foo.o bar.o-o foobar

$./foobar
 The 2nd one

Reference Address: http://www.linuxidc.com/Linux/2012-12/75804.htm

64-bit Ubuntu system using assembler NASM and C language

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.