please help AHHHH ld and gcc problem ?
Posted: Sun Jan 11, 2009 4:38 pm
Ok so my problem is that I am trying to call a c function from an assembly file.
I am using gcc to compile and ld to link. I am on windows XP intel 4 processor
Asm file
name = callfunc.asm
The c file has just one function in it
name = video.c
I first compile the asm with nasm -f (elf , obj , a.out...) callfunc.asm
and then compile the video.c with gcc -c video.c.
They both compile fine regard less of what I give to -f.
However when I try linking these with ld callfunc.o video.c
I either get
I kind of know what the problem is but don't know how to fix it.
Is their away to tell gcc to compile to obj , or elf ,or aout because I cann't find the switch for it?
Also maybe I should change it to
And compile with nasm -f obj callfunc.asm
But then I run back into the problem of what format gcc -c video.c is an how to change it to obj.
I think gcc only supports elf , coff , macho or a.out , bin or hex formats not obj that is used to create .exe files in windows. I also thought of creating a com file but com files are bin files with org 100h and nasm does not support external references in bin format. WTF , I just want to beable to create an exe that calls my asm function.
I am using gcc to compile and ld to link. I am on windows XP intel 4 processor
Asm file
name = callfunc.asm
Code: Select all
BITS 16
jmp start
greetings db 'Greetings and welcome ',13d,10d,'$'
extern _write_string
start:
mov ax , 25d
mov bx , greetings
push ax
push bx
call _write_string ;[color=#FF0000]This is where I call the c function[/color]
label2:
jmp label2
name = video.c
Code: Select all
/* note this example will always write to the top
line of the screen */
void write_string(int colour, const char *string)
{
volatile char *video=(volatile char*)0xB8000;
while(*string!=0)
{
*video=*string;
string++;
video++;
*video=colour;
video++;
}
return ;
}
and then compile the video.c with gcc -c video.c.
They both compile fine regard less of what I give to -f.
However when I try linking these with ld callfunc.o video.c
I either get
Code: Select all
C:\ASM_PR~1>ld callfunc.o video.o
callfunc.o: file not recognized: File format not recognized
or
C:\ASM_PR~1>ld callfunc.o video.o
c:/djgpp/bin/ld.exe: warning: cannot find entry symbol start; defaulting to 0000
18d0
Is their away to tell gcc to compile to obj , or elf ,or aout because I cann't find the switch for it?
Also maybe I should change it to
Code: Select all
BITS 32 ; really could be 16 or 32
segment data
greetings db 'Greetings and welcome ',13d,10d,'$'
segment code
extern _write_string
..start:
mov ax , 25d
mov bx , greetings
push ax
push bx
call _write_string
label2:
jmp label2 ;loop for ever an us task manger to kill process.
But then I run back into the problem of what format gcc -c video.c is an how to change it to obj.
I think gcc only supports elf , coff , macho or a.out , bin or hex formats not obj that is used to create .exe files in windows. I also thought of creating a com file but com files are bin files with org 100h and nasm does not support external references in bin format. WTF , I just want to beable to create an exe that calls my asm function.