Another undefined reference to _main...
Posted: Wed Sep 12, 2012 1:12 am
I've been attempting to convert the bulk of my current OS project from x86 Assembly over to C and assemble with NASM and compile with MinGW. When linking, I get these errors:
Here's the script I'm compilng, assembling and linking with:
...and my linker script is the following:
When I use nm on main.o, it says that there are two things, one with the symbol 'main' and the other '__main', & I've declared my main function like this:
Here's boot.asm:
Can anyone please provide a solution to this problem?
Thanks guys
Code: Select all
ld: warning: cannot find entry symbol start; defaulting to 00100000
o\main.o:main.c:(.text+0x7): undefined reference to `_main'
Code: Select all
gcc -c main.c -o o\main.o -nostdlib -nostdinc -fno-builtin -fno-stack-protector -fno-leading-underscore
nasm boot.asm -o o\boot.o -fcoff
ld -o bin\kernel.bin o\boot.o o\main.o -Tlink.ld
Code: Select all
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .;
_code = .;
__code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .;
_data = .;
__data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .;
_bss = .;
__bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
_end = .;
__end = .;
}
Code: Select all
int main()
{
return 0xDEADBABA;
}
Code: Select all
MBOOT_PAGE_ALIGN equ 1<<0
MBOOT_MEM_INFO equ 1<<1
MBOOT_HEADER_MAGIC equ 0x1BADB002
MBOOT_HEADER_FLAGS equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
MBOOT_CHECKSUM equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)
[bits 32]
[global mboot]
[extern code]
[extern bss]
[extern end]
mboot:
dd MBOOT_HEADER_MAGIC
dd MBOOT_HEADER_FLAGS
dd MBOOT_CHECKSUM
dd mboot
dd code
dd bss
dd end
dd start
[extern main]
[global start]
start:
push ebx
cli
call main
jmp $
Thanks guys