Let's say I have executables A, B, C, and I have external libraries X, Y, Z
SET(EXTERNAL_LIB X Y Z)
TARGET_LINK_LIBRARIES(A, ${EXTERNAL_LIB})
TARGET_LINK_LIBRARIES(B, ${EXTERNAL_LIB})
TARGET_LINK_LIBRARIES(C, ${EXTERNAL_LIB})
However, if I visualize this (using cmake --graphviz
option, I get a complex bipartite graph with edges from each of the executables A, B, and C to each of开发者_JAVA技巧 the libraries X, Y, and Z.
I was wondering if there's a way to combine all the libraries into one.
All of this depends a bit on your platform, compiler and the type of libraries:
In case, you can build X, Y, Z yourself: Create a new project
XYZ
, built from the aggregated source files of X, Y and Z. But I guess if this was possible, you would not have asked on SO.If you can not rebuild the libs and they were built as a shared libraryy (dll/so), you are out of luck. You could try to write a wrapper library, which hides all the internals of X, Y and Z and which will be used by applications A, B and C.
If they were build as static libs, take a look at this SO question. Because a static lib is not much more than an archive of object files, you may be able to extract the object code from each lib and recombine them with
ar
.
But why would you? Suppose you get a fourth application D, which only depends on X. Then you would need the separate library Y anyway (unless you prefer to unnecessarily link with all libs).
精彩评论