Fwd: Question on generating object files with/without -fpic

Richard Guenther richard.guenther@gmail.com
Mon Jan 18 13:34:00 GMT 2010


---------- Forwarded message ----------
From: chandra reddy <creddym@gmail.com>
Date: Mon, Jan 18, 2010 at 2:32 PM
Subject: Question on generating object files with/without -fpic
To: richard.guenther@gmail.com


Hi Richard,

PS: I am not able to send a email to gcc-help@gnu.gcc.org, so i am
sending this to you. please forward it to respective email alias if
you think it is a valid and meaningful question.

Hi All,

I have an application which needs the following requirement.

I need to build both versions (static and shared) of a library, the
compiler first generates object files .o's and uses 'ar' to create a
static version of the library.
Then, it generates object files .So's (with -fpic and -DPIC options).
Using these .So files 'ld' creates a shared version of the library.

My question is: Can compiler generate two object files .o and .So
(fpic) in a single compilation (parse source file once)?

If it is possible, then some of the parsing time will be saved (this
is significant amount in the total compile time).

As we have many platforms and libraries (building static and shared
versions), I think we can save some significant of build time.

Example: to create the library libabc (libabc.a and libabc.so)

- creating static version of the library "librpd"

$gcc <cflags> -c -o a.o a.c
$gcc <cflags> -c -o b.o b.c
$gcc <cflags> -c -o c.o c.c
$ar cq libabc a.o b.o c.o

- creating shared version of the library "librpd"

$gcc <cflags> -fPIC  -DPIC -c -o a.So a.c
$gcc <cflags> -fPIC  -DPIC -c -o b.So b.c
$gcc <cflags> -fPIC  -DPIC -c -o c.So c.c
$gcc <ldflags>  -o libabc.so -Wl,-soname,libabc.so  a.So b.So c.So


Would it be possible to the compiler  to generate two object
files:.<file>.o (general obj file) and <file>.So (obj file with -fpic)
in single compilation?
If so, I think there would be lot compile time reduction for building
these libraries.

Thanks
-Chandra



More information about the Gcc-help mailing list