Jump to content

How do you create executables with NASM?

- - - - -

  • Please log in to reply
4 replies to this topic

#1
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
I've only been able to assemble a program into an object file. What is the option to convert an object file into an executable?

This is the command I use:

nasm -f elf file.s


This creates an object file called file.o. I already tried using the -o option. It still creates an object file, but with a different filename.

I tried converting the object file to an executable like this:


nasm -f elf file.o -o prog


It produces this error message:

first.o:1: error: label or instruction expected at start of line


This is the error message when I try to run the object file:

bash: ./first: cannot execute binary file


I hope this is enough information.
Programming is a journey, not a destination.

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
nasm -felf -o mycode.o mycode.asm
gcc -o myexe mycode.o

That's the most basic form. If you have to link to any other libraries you have to specify them yourself.
sudo rm -rf /

#3
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
Isn't there also an LD syntax?

#4
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
The code I was trying to assemble uses external C libraries. That's why I got an error when I tried linking the object file with gcc. Unfortunately, I don't know the names of the libraries storing the C Standard Library code, or the path to glibc, if all the Standard Library functions are defined there.
Programming is a journey, not a destination.

#5
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Using GCC automatically links the standard C libraries into the program. It should, at least. It has always worked for me.
Latinamne loqueris?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users