1

so I know that you can't depend a static library to another one but i was wondering if there is something that lets me combine them together. I am trying to setup a game engine project file in vstudio 2019 and i want to compile it as a static library. I need in some way to combine it with SDL 2 library because I want create some systems using SDL. Is there a way I can do that? Thanks for the help.

  • See [Linking static libraries to other static libraries](https://stackoverflow.com/questions/2157629/linking-static-libraries-to-other-static-libraries) – dxiv May 08 '20 at 22:40
  • Just add the .lib file to your project and it automagically gets merged into yours. Project > Add Existing Item > pick std2.lib – Hans Passant May 08 '20 at 23:30
  • I suggest you could try to use [Managing a Library](https://learn.microsoft.com/en-us/cpp/build/reference/managing-a-library?redirectedfrom=MSDN&view=vs-2019) command to extract all the object files from all libraries and then use it again to combine them all into a new library. – Jeaninez - MSFT May 11 '20 at 07:17

2 Answers2

3

When creating a library, you can specify "Additional dependencies" in the "Librarian" properties of the project. The dependency may be another library. Also set "Link Library Dependencies" to "Yes" so that the whole library is included.

1

Sure you can have one static library depend on another. A static library is, roughly, a collection of independent compiled objects, with a "settling" of their provided and required symbol table. Those symbols that aren't found within the static library itself continue to be dependencies, which may well be provided by another static library.

Depending on your platform, there are tools for working with compiled libraries. On Unix-like operating systems, you would use the ar utility to combine static libraries ("archives") in various ways:

How to merge two "ar" static libraries into one?

On windows, there's the LIB.EXE tool. See:

How to merge two windows vc static library into one

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • My operating system is windows 10. Do these tools combine the libraries after they are compiled, can i implement them in some way with my visual studio project? I don't really understand this. –  May 08 '20 at 22:46
  • 1
    You can do a post build step that calls LIB.exe – drescherjm May 08 '20 at 22:55
  • @Cinsi: 1. Yes, they combine libraries that have already been compiled 2. I'm not much of a Windows and MSVC guy, so I don't know. But drescherjm says that you can. – einpoklum May 09 '20 at 07:36