Sunday, October 24, 2021

[SOLVED] Adding shared libraries to static library in gcc

Issue

I am creating static library with gcc using: ar rcs libMylib.a objA.o objB.o objC.o

  1. How to add shared libraries to the static library, in other words what is the equivalent to the -lcuda -lopencv_core option when creating static library?

  2. what, if any, is the equivalent to gcc option -Wl,--no-undefined when creating static library?


Solution

Static library is an archive (collection) of object files. Therefore, external symbols remain unresolved. Same as when creating a single object file.

Only when you create an executable or dynamic shared library, you'll fail (or get a warning) for unresolved symbols.



Answered By - Eliyahu Machluf