linker question
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > linker question




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    linker question  
Chris Slominski


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-22-04 12:55 PM

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







[ Post a follow-up to this message ]



    Re: linker question  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-22-04 12:55 PM

"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 signatur
e.
> My build command has the -L <path to local lib> and -l <local lib> switche
s.
> 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 fro
m
> 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





[ Post a follow-up to this message ]



    Re: linker question  
Chris Slominski


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-22-04 12:55 PM


"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







[ Post a follow-up to this message ]



    Re: linker question  
Jens.Toerring@physik.fu-berlin.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-22-04 11: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





[ Post a follow-up to this message ]



    Re: linker question  
manugarg


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-22-04 11: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






[ Post a follow-up to this message ]



    Re: linker question  
Joe Chung


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-22-04 11: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")))





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:09 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register