Linking error

This is a discussion on Linking error within the Tech Board forums, part of the Community Boards category; Im using GCC and getting an error linking, Originally Posted by ld.exe loader.o: In function 'loader': loader.s: (.text+0x14): undefined reference ...

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189

    Linking error

    Im using GCC and getting an error linking,
    Quote Originally Posted by ld.exe
    loader.o: In function 'loader':
    loader.s: (.text+0x14): undefined reference to 'kmain'
    here are the source files -

    loader.s (asm)
    Code:
    global loader ; making entry point visible to linker
    extern kmain ; kmain is defined in kernel.o
    ; setting up the Multiboot header
    MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
    MEMINFO equ 1<<1 ; provide memory map
    FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
    MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
    CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
    section .text
    align 4
    MultiBootHeader:
    dd MAGIC
    dd FLAGS
    dd CHECKSUM
    ; reserve initial kernel stack space
    STACKSIZE equ 0x4000 ; that's 16k.
    loader:
    mov esp, stack+STACKSIZE ; set up the stack
    push eax ; pass Multiboot magic number
    push ebx ; pass Multiboot info structure
    call kmain ; call kernel proper
    hlt ; halt machine should kernel return
    section .bss
    align 32
    stack:
    resb STACKSIZE ; reserve 16k stack on a quadword boundary
    kernel.cpp
    Code:
    void kmain(void* mbd, unsigned int magic){
    // this is to stop compiler warnigns durign development
    mbd;
    magic;
    }
    my linker file
    Code:
    ENTRY (loader)
    SECTIONS{
    . = 0x00100000;
    .text :{
    *(.text)
    }
    .rodata ALIGN (0x1000) : {
    *(.rodata)
    }
    .data ALIGN (0x1000) : {
    *(.data)
    }
    .bss : {
    sbss = .;
    *(COMMON)
    *(.bss)
    ebss = .;
    }
    }
    and my link sequence
    Code:
    nasm -f elf -o loader.o loader.s  
    gcc -o kernel.o -c kernel.cpp -Wall -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs  
    ld -T linker.ld -o kernel.bin kernel.o loader.o
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,663
    If you do
    nm kernel.o
    You'll find that your kmain has been name-decorated because you named it .cpp
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    :bow:

    yes that was it, although it did the same thing when I compiled it as .c

    its now named __Z5kmainv

    so I updated the extern and call lines and it linked just fine now

    now to test it out



    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,663
    You did something wrong if it's still decorated after compiling it as a .c file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Salem View Post
    You did something wrong if it's still decorated after compiling it as a .c file.
    Turns out I was using the wrong compiler, I was trying to compile for an ELF target, and i was using the MinGW version of GCC. After I built a cross compiler it worked fine.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21