8

2 つの静的ライブラリをマージする大きな静的ライブラリを構築しようとしています。現時点では、「ar」コマンドを使用して、たとえば「aa」と「ba」からオブジェクトを抽出し、「ar」を使用してこれらのオブジェクトを再構築しています。

$ ar x a.a
$ ar x b.a
$ ar r merged.a *.o

残念ながら、aaには同じ名前の異なるオブジェクトが含まれているため、私の目的には適していません。「ar」コマンドは、繰り返されるオブジェクトを抽出し、既に抽出されたものを同じ名前に置き換えます。同じ名前でも、これらのオブジェクトには異なるシンボルがあるため、置換されたファイルとともに一部のシンボルが欠落しているため、未定義の参照が発生します。

私は元のオブジェクトにアクセスできず、すでに「ar xP」と「ar xv」、および多くの「ar stuff」を試しました。これらのライブラリをマージする方法を示すのを手伝ってくれる人はいますか?

前もって感謝します。

4

4 に答える 4

2

「ar p」を試してみましたが、友人と話したところ、次の python ソリューションの方が優れていると判断されました。繰り返しオブジェクトファイルを抽出できるようになりました。

def extract_archive(pathtoarchive, destfolder) :

    archive = open(pathtoarchive, 'rb')

    global_header = archive.read(8)
    if global_header != '!<arch>\n' :
        print "Oops!, " + pathtoarchive + " seems not to be an archive file!"
        exit()

    if destfolder[-1] != '/' :
        destfolder = destfolder + '/'

    print 'Trying to extract object files from ' + pathtoarchive

    # We don't need the first and second chunk
    # they're just symbol and name tables

    content_descriptor = archive.readline()
    chunk_size = int(content_descriptor[48:57])
    archive.read(chunk_size)

    content_descriptor = archive.readline()
    chunk_size = int(content_descriptor[48:57])
    archive.read(chunk_size)

    unique_key = 0;

    while True :

        content_descriptor = archive.readline()

        if len(content_descriptor) < 60 :
            break

        chunk_size = int(content_descriptor[48:57])

        output_obj = open(destfolder + pathtoarchive.split('/')[-1] + '.' + str(unique_key) + '.o', 'wb')
        output_obj.write(archive.read(chunk_size))

        if chunk_size%2 == 1 :
            archive.read(1)

        output_obj.close()

        unique_key = unique_key + 1

    archive.close()

    print 'Object files extracted to ' + destfolder + '.'
于 2012-02-09T17:27:01.323 に答える
0

重複する可能性のあるオブジェクトを上書きせずに、多くのライブラリを 1 つの新しいライブラリにマージする C++ コードは次のとおりです

于 2015-01-11T16:41:31.197 に答える
0

オブジェクトの名前を変更できます。それらの名前は、リンク中は何の意味もありません。これはうまくいくはずです:

 mkdir merge-objs &&
 cd merge-objs &&
 ar x ../a.a &&
 for j in *.o; do mv $j a-$j; done &&
 ar x ../b.a &&
 ar r ../merged.a *.o &&
 cd .. && rm -rf merge-objs
于 2012-02-08T22:26:48.533 に答える