Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

trouble calling C++ functions

$
0
0
I wrote a small toy kernel in C++, and a small graphics library.
now I wanted to call this function from assembly, but that doesn't really work out.
I can compile the cpp en asm files into object code, but when I link them, it keeps saying
'error, undefined reference to _main'
the assembly code looks like this:
;loader.asm
[BITS 32] ;protected mode
global start
extern _main ;this is our C++ code
start:
  call _main ;call the int main(void) code in C++ source
  cli ;clear interrupts
  hlt ;halt the CPU


the kernel cpp file looks like this:
#include "video.h"
int main(void)
{
    video vid; //local variable
    vid.Write("hello world!");
}


and since I'm using a linker file, I'll give that one as well:
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text 0x100000 :
  {
    code = .;_code = .;__code = .;
    *(.text)
    . = ALIGN(4096);
  }
  
  .data :
  {
    data = .;_data = .;__data = .;
    *(.data)
    . = ALIGN(4096);
  }
  
  .bss :
  {
    bss = .;_bss = .;__bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  
  end = .;_end = .; __end = .;
}



I would really like to know why I can't call '_main'

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>