Reputation: 75
I'm starting out with programming in Assembly in x86 and I'm following a guide for that. I'm using gas to compile on a linux virtual machine.
I'm trying to run a simple empty program where main routine exits the program immediately. That's the first task in the guide I'm following. My code is saved in a file hello.s and it looks like this:
.global main
main:
movq %rsp, %rbp
mov $0, %rdi
call exit
In the terminal I navigate to the directory of the file and try to run it like this:
gcc -o hello.o hello.s -no-pie ./hello.s
I get an error saying:
/tmp/cc62hr1F.o: In function 'main':
(.text+0x0): multiple definition of 'main'
/tmp/ccwMutY1.o(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
What does this error mean and how to fix it? Thank you in advance.
Upvotes: 1
Views: 510
Reputation: 75
EDIT/SOLUTION: I figured out what was wrong. In the terminal I should run it like this:
gcc -o hello.o hello.s -no-pie
./hello.o
These are two seperate commands. I wrote them in one line. And the file to run has to have the extensions .o not .s
Upvotes: 1