|
Home > Archive > Unix Programming > July 2004 > linker question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Chris Slominski 2004-07-22, 7:55 am |
| Group,
I have a situation where I want to use a UNIX defined system function,
but a locally developed library also has a function with the same signature.
My build command has the -L <path to local lib> and -l <local lib> switches.
How do I tell the linker to use the function defined in the default system
library instead of the version in the local library. Note I need other
functions from the local library, so I can't just remove the reference from
my link command.
Thanks,
Chris
| |
| Måns Rullgård 2004-07-22, 7:55 am |
| "Chris Slominski" <cjs@jlab.org> writes:
> Group,
> I have a situation where I want to use a UNIX defined system function,
> but a locally developed library also has a function with the same signature.
> My build command has the -L <path to local lib> and -l <local lib> switches.
> How do I tell the linker to use the function defined in the default system
> library instead of the version in the local library. Note I need other
> functions from the local library, so I can't just remove the reference from
> my link command.
Are you using static or dynamic linking? Normally the linker will
search the libraries in the order they are given on the command line.
The safe solution is to change the name of the non-system function and
avoid the conflict entirely.
--
Måns Rullgård
mru@kth.se
| |
| Chris Slominski 2004-07-22, 7:55 am |
|
"Måns Rullgård" <mru@kth.se> wrote in message
news:yw1xllhcjiis.fsf@kth.se...
> "Chris Slominski" <cjs@jlab.org> writes:
>
function,[vbcol=seagreen]
signature.[vbcol=seagreen]
switches.[vbcol=seagreen]
system[vbcol=seagreen]
from[vbcol=seagreen]
>
> Are you using static or dynamic linking? Normally the linker will
> search the libraries in the order they are given on the command line.
> The safe solution is to change the name of the non-system function and
> avoid the conflict entirely.
>
> --
> Måns Rullgård
> mru@kth.se
I have no control over the locally defined library, so removing that
definition of the symbol is not an option. I understand that the linkrer
searches the libraries in the order that they appear on the command line,
but since the default system library is not explicitly mentioned, I can't
control the order. Should/can I explicitly list the default library? What is
its name? Is it /usr/lib/libC.a ?
Chris
| |
| Jens.Toerring@physik.fu-berlin.de 2004-07-22, 6:01 pm |
| Chris Slominski <cjs@jlab.org> wrote:
> "Måns Rullgård" <mru@kth.se> wrote in message
> news:yw1xllhcjiis.fsf@kth.se...
> function,
> signature.
> switches.
> system
> from
[vbcol=seagreen]
> I have no control over the locally defined library, so removing that
> definition of the symbol is not an option. I understand that the linkrer
> searches the libraries in the order that they appear on the command line,
> but since the default system library is not explicitly mentioned, I can't
> control the order. Should/can I explicitly list the default library? What is
> its name? Is it /usr/lib/libC.a ?
I guess you should get it by simply specifying "-lc" as the first
library on the command line, at least that should be worth a try.
An alternative would be to create a linker version script where
you declare the function as local, so it won't be used in linking.
But none of this will make the functions within the library calling
that function you want to get rid of calling the function by the
same name from libc.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
| |
| manugarg 2004-07-22, 6:01 pm |
| If you have a compiler similar to gcc, you can stop it from including
standard libraries by passing -nostdlib option.
On passing this option, compiler doesn't link standard libraries by
default. But then you'll have to explicitly declare compiler libraries
also. For gcc, I use a command similar to the following to compile a
program without default libs:
gcc -o test /usr/lib/crt1.o /usr/lib/crti.o \
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/crtbegin.o test.o -lc \
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/crtend.o \
/usr/lib/crtn.o -nostdlib
Here test.o is the object file for my program. -lc option tells the
compiler to link against standard c libraries. Rest of the libs are
compiler libraries, which are required for all programs. (\ is for line
continuation).
Path and libraries may be different on your platform, so change the
command according to your need.
Cheers!
Manu Garg
http://manugarg.freezope.org
Chris Slominski wrote:
> function,
> signature.
lib>[vbcol=seagreen]
> switches.
default[vbcol=seagreen]
> system
other[vbcol=seagreen]
reference[vbcol=seagreen]
> from
> I understand that the linkrer
> searches the libraries in the order that they appear on the command
line,
> but since the default system library is not explicitly mentioned, I
can't
> control the order. Should/can I explicitly list the default library?
What is
> its name? Is it /usr/lib/libC.a ?
>
> Chris
| |
| Joe Chung 2004-07-22, 6:01 pm |
| "Chris Slominski" <cjs@jlab.org> writes:
> "Måns Rullgård" <mru@kth.se> writes:
>
> I have no control over the locally defined library, so removing
> that definition of the symbol is not an option. I understand
> that the linkrer searches the libraries in the order that they
> appear on the command line, but since the default system
> library is not explicitly mentioned, I can't control the
> order. Should/can I explicitly list the default library? What
> is its name? Is it /usr/lib/libC.a ?
>
> Chris
It would be helpful to let us know the name of the function, and
the flavor of Unix you're on, and whether you're doing this in C
or C++. I'm assuming C because it's very hard for C++ names to
clash at the object file level, but you write libC.a, which is a
C++ library. The C library is brought in with -lc (note lower
case).
It's too bad you have no control over the naming of the local
function, because that indeed is the best solution.
You can try explicity putting -lc in front of your local library,
and that may work depending on whether you're linking statically
or dynamically. Depending how you invoke your compiler, you can
see the complete link line (with all system libraries). With
gcc, for example, add the -v option to the link invocation.
Lastly, if you can get your hands on GNU binutils, you can use
the objcopy command to rename the clashing function in your local
library, thusly:
objcopy --redefine-sym origsym=newsym origlib newlib
To do this right, you'll need to know the exact name of the
original symbol in origlib, (which you can find out using nm).
Depending on the flavor of Unix, there may be a leading
underscore (or other decorations) in front of the original symbol
name. When you rename origsym, you should keep all those
decorations in your newsym,
e.g. --redefine-sym __malloc=__mymalloc
After the renaming, just make sure to use newsym in your source
code and link against newlib instead of origlib.
-jc
--
(apply 'concat (reverse (list "com"
(char-to-string 46) "yahoo"
(char-to-string 64) "joechung")))
|
|
|
|
|