Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

How can I turn multiple archive files into one big archive file on Linux (using binutils ar and / or GCC).

I tried doing things like ar rcs libbig.a libsmall1.a libsmall2.a and it doesn't work (the resulting libbig.a is empty).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just tried this on my machine and the problem seems to be that you need to extract the objects from the archives before adding them to the new archive:

ar x libsmall1.a
ar x libsmall2.a
ar rcs libbig.a *.o

Simply running ar rcs like you did produced an archive which contained two .a files, but tools (e.g. nm) were unwilling to look deeper into these files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...