Search code examples
cgccldbinutils

How to make fake proxy Import library


I remember finding *.a library that doesn't contain any object but instead a list libraries (as a plain text?), something like: -liconv -lm

So that when gcc encounter it, both library will be searched for linking.

Is there such trick? pretty sure it was working that time, but I don't know how to make it now.


Solution

  • Is your linker from binutils? binutils ld supports .a files as implicit linker scripts:

    If you specify a linker input file which the linker can not recognize as an object file or an archive file, it will try to read the file as a linker script. If the file can not be parsed as a linker script, the linker will report an error.

    A linker script does not have to be complicated, it can be as simple as this (for glibc's libc.so):

    /* GNU ld script.  */
    OUTPUT_FORMAT(elf64-x86-64)
    GROUP ( …/libc.so.6 …/libc_nonshared.a AS_NEEDED ( …/ld-linux-x86-64.so.2 ) )
    

    Or you can just use INPUT to delegate things to ld:

    If you use ‘INPUT (-lfile)’, ld will transform the name to libfile.a, as with the command line argument ‘-l’.