Aggregate static libraries

醉酒当歌 提交于 2019-12-12 16:27:08

问题


I try to aggregate multiple .a files into a single one. The command is the following:

TARGET=libnumpy.a
DIR=build/lib.linux-x86_64-2.6/numpy
FILES=$(DIR)/core/_sort.a $(DIR)/core/multiarray.a $(DIR)/core/umath.a $(DIR)/core/scalarmath.a $(DIR)/core/umath_tests.a $(DIR)/core/multiarray_tests.a $(DIR)/lib/_compiled_base.a $(DIR)/numarray/_capi.a $(DIR)/fft/fftpack_lite.a $(DIR)/linalg/lapack_lite.a $(DIR)/random/mtrand.a

all:
    ar cr $(TARGET) $(FILES)

But the resulting library libnumpy.a is unusable. When trying to compile something with it, I get

libnumpy.a: could not read symbols: Archive has no index; run ranlib to add one

(I tried to run ranlib but it didn't solve the problem)

When doing nm libnumpy.a I get

nm: _sort.a: File format not recognized
nm: multiarray.a: File format not recognized
nm: umath.a: File format not recognized 
nm: scalarmath.a: File format not recognized
nm: umath_tests.a: File format not recognized
nm: multiarray_tests.a: File format not recognized
nm: _compiled_base.a: File format not recognized
nm: _capi.a: File format not recognized
nm: fftpack_lite.a: File format not recognized
nm: lapack_lite.a: File format not recognized
nm: mtrand.a: File format not recognized

What's wrong with this?


回答1:


As @Mat mentioned:

#ar x <archivefile>  / * Repeat for all archives */
#ar cv <all Obj fiels>



回答2:


You're adding archive files to an archive file. You shouldn't be doing that, you should be putting object files in an archive.

One way around that if you have GNU ar is to create thin archives (with the T switch):

GNU ar can optionally create a thin archive, which contains a symbol index and references to the original copies of the member files of the archives. Such an archive is useful for building libraries for use within a local build, where the relocatable objects are expected to remain available, and copying the contents of each object would only waste time and space. Thin archives are also flattened, so that adding one or more archives to a thin archive will add the elements of the nested archive individually. The paths to the elements of the archive are stored relative to the archive itself.

Otherwise, archive all the individual .o files that comprise your original .a files.



来源:https://stackoverflow.com/questions/9547061/aggregate-static-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!