$ 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