开发者

UNIX: Static library linked to a static library [duplicate]

This question already has an answer here: Closed 10 years ago.

Possible Duplicate:

How to pack multiple library archives (.a) into one archive file?

I have a situation where I must provide only a single static library (.a file) to an executable file to build it.

However, I split this lib in 2 parts because one part is common to other executable files and the other is needed only by one.

So now I have lib1 (for exe1) and lib2 (for all exes)

The problem is that I can't provide two libs, so I must merge for exe1, lib2 into lib1

I tried my compiling the lib1.o with -llib2 but even if it works, it looks like if nothing happened

Are there any other way? I'm can only think about using r开发者_如何学JAVAaw object files but I don't like this idea


There's no need for two static libraries; when a static library is used, only the functions (or variables) that are needed are copied to the executable - unlike a shared library where everything in the library is accessible to the executable.

Mechanically, the other question referenced describes what you need to do:

  • Extract all the object files from one library
  • Add them to the other library

Or:

files=$(ar t lib1.a)
ar x lib1.a
ar r lib2.a $files
rm -f $files lib1.a


You can even compile each source file, produce all .o and create two different libs by using ar. The whole library will be produced using all .o (the ones you put in lib1.a and lib2.a together), the smaller one will use just a reduced set of .o files. Than... a single Makefile, .o files produced once, two libraryes coming out from this job: the complete one (libaplus2.a) and the reduced one (lib1.a).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜