This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How to avoding compiling unreferenced code into .o target file
- From: Markus Trippelsdorf <markus at trippelsdorf dot de>
- To: kipade <kipade at 163 dot com>, g@x4
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 31 Aug 2017 11:39:14 +0200
- Subject: Re: How to avoding compiling unreferenced code into .o target file
- Authentication-results: sourceware.org; auth=none
- References: <65beb0b1-4d63-6ee8-3c6b-de7360c5430c@163.com>
On 2017.08.31 at 17:31 +0800, kipade wrote:
> Hi all,
> If there is a way to avoiding assemblly unreferenced entry into .o target
> file?
> The issue is from such condition:
> Dynamic library B is dependent on Dynamic library A: the source find b.c in
> library B includes a header file from A, which named a.h, here, there was a
> inlined function within a.h, however, b.c just include a.h and without any
> code decleared within a.h. So, the target .o file of b.c would not generate
> any code for the inline function, just leave an entry for that function.
>
> The problem is, when the b.c was packed as a shared dynamic library and
> was used by the third executable client, gcc would complain it can't find
> the reference of the inline function entry decleared in a.h, although which
> would not be used by the library B.
>
> Finnaly, I have to remove the include instruction in b.c to avoiding such
> linking error. But, I don't know how to resolve that issue if there is a c.c
> which have to include a.h because it use parts of entries decleared in
> a.h. (I can't modify any code of library A, because it's a foreign library)
There is nothing gcc specific in you question so it is off-topic for this
list. Just read Drepper's whitepaper:
https://www.akkadia.org/drepper/dsohowto.pdf
--
Markus