Static library built for archive which is not the architecture being linked (x86_64)

后端 未结 5 793
终归单人心
终归单人心 2021-02-04 03:20

I am experiencing what seems to be the same problem when I try to compile two different programs. Each of them creates first a static library and then the main application linki

5条回答
  •  灰色年华
    2021-02-04 04:17

    Thanks to this question with the same problem, I could look into this problem. I don't have much experience with static libraries, but I'll try to explain the problem.

    For some reason, Mac OSX ar utility creates "subdirectories" in the static library. For example, building the sba library, the steps of make to build the static library from the object file is:

    ar crv libsba.v1.5.a sba_levmar.o sba_levmar_wrap.o sba_lapack.o sba_crsm.o sba_chkjac.o
    

    After that, if I look at the contents of the static library, I saw that in addition to the files, there are some strange directorios:

    $ ar -t libsba.v1.5.a 
    __.SYMDEF
    /
    //
    sba_levmar.o/
    /0
    sba_lapack.o/
    sba_crsm.o/
    sba_chkjac.o/
    sba_levmar.o
    sba_levmar_wrap.o
    sba_lapack.o
    sba_crsm.o
    sba_chkjac.o
    sba_levmar.o
    sba_levmar_wrap.o
    sba_lapack.o
    sba_crsm.o
    sba_chkjac.o
    

    If we try to extract those files, we get some errors regarding the subdirectories:

    $ ar -x libsba.v1.5.a 
    ar: /: Is a directory
    ar: //: Is a directory
    ar: sba_levmar.o/: Not a directory
    ar: /0: Permission denied
    ar: sba_lapack.o/: Not a directory
    ar: sba_crsm.o/: Not a directory
    ar: sba_chkjac.o/: Not a directory
    

    Now, if we create the lib again with the extracted object files, it will work:

    $ ar crv libsba.v1.5.a lib_o/*.o
    a - lib_o/sba_chkjac.o
    a - lib_o/sba_crsm.o
    a - lib_o/sba_lapack.o
    a - lib_o/sba_levmar.o
    a - lib_o/sba_levmar_wrap.o
    
    $ ar -t libsba.v1.5.a
    __.SYMDEF SORTED
    sba_chkjac.o
    sba_crsm.o
    sba_lapack.o
    sba_levmar.o
    sba_levmar_wrap.o
    

    I don't understand the reason at all, but it worked for me.

提交回复
热议问题