2
votes

I'd like to build both static and shared libraries with Autotools. However, this results in a double compile, as described in this question.

Is there a way to avoid this? My first though was to enable -fPIC and -DPIC even when building the static library. However, that didn't work.

I understand that -fPIC is suboptimal for static libraries, but I'm more concerned with build time than runtime efficiency for this particular project.

1

1 Answers

0
votes

According to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28811 there was a g++/libstdc++ bug that prevented PIC code from linking statically. Perhaps that's the problem you were seeing? It's supposed to be fixed in 4.7.

That aside, the normal approach is to only do one style (static or shared as convenient) build during development and then when you do a release just take the extra build time and generate two separate builds, one with PIC and one without.