0

I'm publishing a multi-platform library and it's working everywhere except Linux. There's probably a way to do what I need, but I'm not seeing it and hoping someone here can help.

My library consists of two projects, 'subLibrary.lib' and 'library.lib' on Windows (for example). I build 'subLibrary' then link it into 'library' for distribution. Consumers only have to link with 'library' to get everything, including what's in 'subLibrary'.

Every other platform works the same -- I publish one giant 'library.a' that contains everything and consumers link with it, not having to know about any of the lower-level dependencies.

When building a standard executable on Linux, my link command must specify not only 'library.a' but also every dependency of it. This is because intermediate libraries leave symbols unresolved until later.

What I want to do is make it the same as the other platforms so the consuming executable only has to link with 'library.a' and that library contains everything it needs.

I know this will make the library larger, but it's the only way to ensure dependency resolution and build time for everyone.

Bungles
  • 1,969
  • 2
  • 25
  • 54
  • 4
    On neither Windows nor Linux can you link a static library to another static library. You can use the `ar` tool or similar to construct a concatenation of two libraries, but that is not linking. –  Apr 24 '18 at 20:59
  • For the analogous tool on Windows, see https://stackoverflow.com/questions/13492365/how-to-merge-two-windows-vc-static-library-into-one and https://msdn.microsoft.com/en-us/library/7ykb2k5f.aspx – Paul Sanders Apr 25 '18 at 05:27

1 Answers1

0

On unix a library is simply a collection of all the object files. You can add more files to the library with AR, but you do need to be careful of file name conflicts.

Gem Taylor
  • 5,381
  • 1
  • 9
  • 27