is there any way to change the order of name resolution in linking (aside from putting the libraries in the right order?)

Ian Lance Taylor iant@google.com
Thu Sep 27 05:24:00 GMT 2012


On Wed, Sep 26, 2012 at 10:09 PM, Dan Hitt <dan.hitt@gmail.com> wrote:
> I am building some code and i need a certain library to be linked in
> last, so it can resolve symbols left unresolved earlier.
>
> Normally the way to do this would be to just list that library last
> on the command line.
>
> However, i'm using a build system which constructs all the
> commands for me, and although it makes a provision for
> adding extra arguments to the linker, they end up going first.
>
> So although i can add arguments to the link, i cannot order
> them the way i want, and i get unresolved symbols as a consequence.
>
> So i'm wondering if there's any argument i can slip in that will change
> the order that gcc runs through the libraries in.

I'm not aware of any such option.

One thing that may work, if you are using the GNU linker or something
reasonably compatible, is
    -Wl,--whole-archive,-lMYLIB,-Wl,--no-whole-archive

That will link in the entire contents of the library, so all the
symbols defined in the library will be available.

Ian



More information about the Gcc-help mailing list