Article View: gnu.gcc.help
Article #41732Re: Linking
From: Nathan Hawkins
Date: Wed, 21 Feb 1996 00:00
Date: Wed, 21 Feb 1996 00:00
25 lines
1674 bytes
1674 bytes
Dinkar N Bhat (bhat@news.cs.columbia.edu) wrote: : Can someone help me with this? I have a function f(..) called in main(), : and it resides in file g.c, also in libtest.a : : When I specify gcc main.c g.o -ltest, I want it to pickm the definition : of f(..) from g.c, instead of libtest.a. When I just say : gcc main.c -ltest, I would like the defintion from libtest.a : : I keep getting errors saying "multiply defined function name". It used : to work with cc, and also I heard it works with gcc. Do I have to : specify some other option for linking? There is a way to do this. (Although, it might not do exactly what you want.) You need to do two links, the first one with -r, linking all your files together. Then run strip --strip-unneeded on the resulting file. After that, you can link that object file with your libraries. What this will do is link all your .o files together into one, and remove all the resolved symbols. Then, when you link with the libraries, your function f(..) will already have been resolved, and it's name removed from the symbol table. The bad thing about this method is that it makes debugging harder... Also, there would then be no way to call function f(..) from the library. But I hope this helps. *utsl*
Technical Details
Message-ID:
<4gfjsh$akk@news.one.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<4gdsao$jl4@saxophone.cs.columbia.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,99152aad5fee1734 X-Google-Attributes: gid11318c,public From: utsl@one.net (Nathan Hawkins) Subject: Re: Linking Date: 1996/02/21 Message-ID: <4gfjsh$akk@news.one.net> X-Deja-AN: 140472396 references: <4gdsao$jl4@saxophone.cs.columbia.edu> organization: OneNet Communications HUB News Server newsgroups: gnu.gcc.help