1

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.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
olddog55
  • 13
  • 2

1 Answers1

0

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’.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • yes it's binutils, but I don't think it is complicated linker script, I don't remember get strange message such `treating as linker script`. That time my impression was "Whoever make this lib certainly tricked gcc!" – olddog55 Nov 25 '17 at 09:27
  • I don't think you get a warning, and linker scripts can actually be quite short. All that section placement stuff is optional. – Florian Weimer Nov 25 '17 at 09:45
  • Ahh you're right it must be that, must be forgot about the messages – olddog55 Nov 25 '17 at 10:22
  • 1
    it was oneliner text `INPUT(-liconv -lm)` saved as libxx.a! thanks – olddog55 Nov 25 '17 at 10:29