https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64390
Bug ID: 64390 Summary: "-shared" does not resolve symbols from lto generated archives Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: htl10 at users dot sourceforge.net Upgrading to 4.9.2 from 4.8.x, building R (http://www.r-project.org) with fto fails. ("./configure --enable-lto AR=gcc-ar"). Specifically, it builds a few static archives of external libraries then tries build a shared libraries out of it. A simplified procedure is like this: gcc -flto -c -o routine1.o routine1.c ... gcc -flto -c -o used_by_routine1.o used_by_routine1.c ... gcc-ar cr libextra.a used_by_routine1.o ... ... gcc -shared -o liboutput.so routine1.o ... libextra.a ... the output shared library is not able to resolve any symbols with libextra.a's content. I found two workarounds: - putting all the dependent *.o on the command line instead of the archive itself. - prepending/appending the extra libraries with the whole archive linker directives: i.e. "-Wl,--whole-archive ../extra/tre/libtre.a -Wl,--no-whole-archive" I realise generating shared libraries from static archive is daft, but that's how R is built.