prog1.c
Code: Select all
#include <stdio.h>
extern int func1( int ) ;
int main()
{
int i = func1( 3 ) ;
printf( "Hi this is %d " , i ) ;
return 0 ;
}
and
prog2.asm
Code: Select all
global _func1
_func1:
mov ax , [esp + 4]
ret 4
Code: Select all
nasm -f coff prog2.asm
Then I compile prog1.c
Code: Select all
gcc -c prog1.c
But my problem is when I link the 2 likes I get
Code: Select all
C:\asm2>ld prog1.o prog2.o -o output.exe
c:/djgpp/bin/ld.exe: warning: cannot find entry symbol start; defaulting to 0000
18d0
prog1.o(.text+0x22):prog1.c: undefined reference to `func1'
prog1.o(.text+0x39):prog1.c: undefined reference to `printf'
but that just gave me a ton of unresolved references...etc
I declared the func1 external in my c program so the linker should find it in prog2.o.
I just don't get what is going wrong. I have tried coff because when I objdump the 2 files they seem to be of the coff type.
Note I didn't make a linker script for it put I thought the default entry point would be main.
I can clear it up by setting the default to main I guess.
As for the unresolved references I don't understand it they are in the files being linked.
I used the _func1 for func1 since that is the mangled nameing convention.
Thanks for any help on this one
They are both coff-go32 object format.
If I remove the extern func1 in the main program and just use gcc prog1.c -o output.exe
I get the output.exe which executes fine And displays Hi this is 0
like this
Code: Select all
#include <stdio.h>
//extern int func1( int ) ;
int main()
{
int i = 0 ;
//int i = func1( 3 ) ;
printf( "Hi this is %d " , i ) ;
return 0 ;
}
Either way it is compiling fine it is linking issues that I cann't figure out.