Hi,
I'm having a problem with ld.
I have my math functions compiled and packed into an archive math.a and use them in functions from memory.a which are used by main.o.
My problem: ld doesn't include the routines from math.a and complains that they are missing, because it then finds references to them in memory.a.
Is this a bug or what?
Thanks,
The Legend
bug in ld? (or what?)
Re: bug in ld? (or what?)
Two things:
1. You may need to do a ranlib on the libraries.
2. Make sure you specify them in the right order:
ld <options> main.o memory.a math.a
Good luck!
1. You may need to do a ranlib on the libraries.
2. Make sure you specify them in the right order:
ld <options> main.o memory.a math.a
Good luck!
Re: bug in ld? (or what?)
>My problem: ld doesn't include the routines from math.a and
>complains that they are missing, because it then finds
>references to them in memory.a
I assume you're not using the functions in memory.a that
use the math code...?
Did you build memory.a from a single C file containing
all of your functions? The "quantum" (smallest unit) of
linkage is the module, and module = file for C.
If you link against one function in a file, you get the
code for all other functions in that file, whether you use
them or not.
Maybe you can take the functions in memory.a that need the
math code and move them to a one or more separate files.
>complains that they are missing, because it then finds
>references to them in memory.a
I assume you're not using the functions in memory.a that
use the math code...?
Did you build memory.a from a single C file containing
all of your functions? The "quantum" (smallest unit) of
linkage is the module, and module = file for C.
If you link against one function in a file, you get the
code for all other functions in that file, whether you use
them or not.
Maybe you can take the functions in memory.a that need the
math code and move them to a one or more separate files.
Re: bug in ld? (or what?)
I'm using the memory functions which access the functions in math.a, if I don't use them ld thinks everything is fine as the math functions are currently not used anywhere else (currently!).>My problem: ld doesn't include the routines from math.a and
>complains that they are missing, because it then finds
>references to them in memory.a
I assume you're not using the functions in memory.a that
use the math code...?
Did you build memory.a from a single C file containing
all of your functions? The "quantum" (smallest unit) of
linkage is the module, and module = file for C.
If you link against one function in a file, you get the
code for all other functions in that file, whether you use
them or not.
Maybe you can take the functions in memory.a that need the
math code and move them to a one or more separate files.
I'll see what ranlib can do and if changing the order helps.
Re: bug in ld? (or what?)
Reversing the order has helped, thanks!
Still I think that ld should behave differently ....
Still I think that ld should behave differently ....
Re:bug in ld? (or what?)
ld is a single-pass linker. As it finds references to undefined lables in a module, it saves them. As those lables are defined, all places that reference them are updated. If it finds a lable that hasn't been referenced yet in any previous module, it will discard it (unless it is referenced in the same module where it's defined).
This is usually how unix linkers work and is not specific to gnu's ld.
At any rate, glad I was able to help!
This is usually how unix linkers work and is not specific to gnu's ld.
At any rate, glad I was able to help!
Re:bug in ld? (or what?)
And why do the unix linkers still work like that?
I think they should change this.
I think they should change this.