how to add new object files at the start in an existing static library

时间:2017-06-09 12:48:14

标签: linux linker static-libraries archive

I have an existing static library libelab.a I want to add two object files obj1.o, obj2.o at the start index in libelab.a

What options with ar command should I use?

man page says that b is the modifier for this task, but I tried to use it as : 'ar rbvs libelab.a obj1.o obj2.o', but following error is given ar: obj1.o: File format not recognized

1 个答案:

答案 0 :(得分:-1)

我意识到我使用了错误的语法。

ar命令的手册页说明了关于修饰符b:

   b   Add new files before an existing member of the archive.  If you use the modifier b, the name of an existing archive member must be present as the relpos argument, before the archive specification.

所以要使用b选项,我必须在库中指定现有的目标文件名,在此之前我希望添加2个新对象。

例如,如果old.o是库中的现有目标文件,则以下是正确的语法:

ar rbvs old.o libelab.a obj1.o obj2.o