I link an object file but it dont recognize the symbols

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

I link an object file but it dont recognize the symbols

Post by earlz »

basically the title says it all, i have an object file made in asm and am trying to link it in codeblocks with mingw/ld and I know it is linking with the object file cause if i change the name it will say file not found but it is as if it wasnt linked because it says undefined reference to anything in the object file and i have opened it in a hex editor to make sure that the symbols were there and they are
here is my code

Code: Select all

//c code
extern void gdt_flush(); //and i call it in a function after this line

;asm code
global _gdt_flush ;i have tried it with and without the underscore
_gdt_flush:
add bx,1 ;this is just here so it does something
ret

if anyone could help me it would be greatly appreciated; hopefully i havent broken my keyboard by the time someone replies to this

edit:
omfg i cant beleive how stupid i am i forgot to put the section .text in it
mods/admins can delete or lock this or whatever
Last edited by earlz on Sat Nov 05, 2005 12:00 am, edited 2 times in total.
User avatar
UnsurpassedBlaze
Posts: 10
Joined: Wed Nov 02, 2005 12:00 am
Location: Somewhere on Earth...

Re: I link an object file but it dont recognize the symbols

Post by UnsurpassedBlaze »

Code: Select all

global _gdt_flush ;i have tried it with and without the underscore
_gdt_flush:
Try doing

Code: Select all

EXTERN _gdt_flush
call _gdt_flush
in your asm code.

Judging from my small knowledge, gdt_flush is an externel command from a dll right? If it's not and you're declaring it yourself you don't have to put extern before it.
The code is only as good as the programmer.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: I link an object file but it dont recognize the symbols

Post by earlz »

no your way off
i was trying to make a pure asm function
the global means to export the symbol so that things that it is linked(other objects) can call the function and the gdt_flush: is just a label and the name of the function and is basically nothing more than a bookmark for where the function is in the compiled code

the extern in the C code basically tells the compiler "ignore that the function is not in the C source code being compiled" and it is put with it at link time and not compiler time; but this does not mean it is loaded at runtime it is loaded at link and if the symbol is not found at link time then you get a nice little undefined reference error

and no this is osdev not dll stuff even though i would kill someone if i could put in dll support in my own os
orb
Posts: 1
Joined: Sun Nov 06, 2005 12:00 am

Re: I link an object file but it dont recognize the symbols

Post by orb »

You were close,

Assuming you are using NASM, try putting the function specifier when declaring _gdt_flush to be a global label. See code below.

You still may have to mess around with the underscore business as that is compiler dependant.

Hope this helps.

Ps, there maybe something else thats wrong with this, only a quick look before i'm off to work.



extern void gdt_flush(); //and i call it in a function after this line

;asm code
global _gdt_flush:function ;i have tried it with and without the underscore
_gdt_flush:
add bx,1 ;this is just here so it does something
ret
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: I link an object file but it dont recognize the symbols

Post by earlz »

did you not read the edit
i said that i didnt have the memory address where it was located right, so the linker would resolve vars differently
Post Reply