problem compiling with gcc -o option
Posted: Mon Aug 11, 2003 7:07 pm
I was going through an assembly tutorial, and I am having a problem now when compiling my assembler code with my C code.
The ASM:
*******************************************
; file: test1.asm
; First assembly program testing the ability
; to store data in the EAX register and print
; it to the screen.
;
; Syntax to create executable using DJGPP:
; nasm -f coff test1.asm
; gcc -o test1 test.o driver.c asm_io.o
%include "e:\djgpp\asm_io.inc"
;
; initialized data should be placed under
; the .data segment
segment .data
;
output1 db "Hello World! ", 0 ;space after string = null terminator
;
;
segment .bss
;
;
segment .text
global _asm_main
_asm_main:
enter 0,0
pusha
; begin program code
mov eax, output1 ; prepare variable for output
call print_string ; invoke asm proc that calls C
; end program code
; all below information required
popa
mov eax,0 ; return back to C
leave
ret
*******************************************
The "C" code:
*******************************************
int asm_main(void);
int main()
{
int ret_status;
ret_status = asm_main();
return ret_status;
}
*******************************************
I guess the way the author intended this to work, was that even though the C funtion asm_main does not exist, when it is linked in or compiled with the ASM code, it'll see the _asm_main global reference and compile OK. I compile the ASM with this command:
nasm -f coff test1.asm
... works ok. However, I try to compile all my files together with gcc with this command:
gcc -o test1 test.o driver.c asm_io.o
... and I get this error:
e:/djgpp/tmp/ccIkRtvO.o(.text+0x11):driver.c: undefined reference to `_asm_main'
collect2: ld returned 1 exit status
Does anyone have any idea what I'm missing here? I am using the DJGPP program files to develop all this, as shown by the author.
The ASM:
*******************************************
; file: test1.asm
; First assembly program testing the ability
; to store data in the EAX register and print
; it to the screen.
;
; Syntax to create executable using DJGPP:
; nasm -f coff test1.asm
; gcc -o test1 test.o driver.c asm_io.o
%include "e:\djgpp\asm_io.inc"
;
; initialized data should be placed under
; the .data segment
segment .data
;
output1 db "Hello World! ", 0 ;space after string = null terminator
;
;
segment .bss
;
;
segment .text
global _asm_main
_asm_main:
enter 0,0
pusha
; begin program code
mov eax, output1 ; prepare variable for output
call print_string ; invoke asm proc that calls C
; end program code
; all below information required
popa
mov eax,0 ; return back to C
leave
ret
*******************************************
The "C" code:
*******************************************
int asm_main(void);
int main()
{
int ret_status;
ret_status = asm_main();
return ret_status;
}
*******************************************
I guess the way the author intended this to work, was that even though the C funtion asm_main does not exist, when it is linked in or compiled with the ASM code, it'll see the _asm_main global reference and compile OK. I compile the ASM with this command:
nasm -f coff test1.asm
... works ok. However, I try to compile all my files together with gcc with this command:
gcc -o test1 test.o driver.c asm_io.o
... and I get this error:
e:/djgpp/tmp/ccIkRtvO.o(.text+0x11):driver.c: undefined reference to `_asm_main'
collect2: ld returned 1 exit status
Does anyone have any idea what I'm missing here? I am using the DJGPP program files to develop all this, as shown by the author.