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

后端 未结 5 795
终归单人心
终归单人心 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:15

    A possible cause is using the GNU ar(1)/ranlib(1) instead of the ones supplied by the Xcode toolchain. Run which -a ar and which -a ranlib to see the what you have in $PATH.

    For example:

    $ which -a ranlib
    /usr/local/bin/ranlib
    /usr/bin/ranlib
    
    $ /usr/local/bin/ranlib --version
    GNU ranlib (GNU Binutils) 2.28.51.20170105
    Copyright (C) 2017 Free Software Foundation, Inc.
    This program is free software; you may redistribute it under the terms of
    the GNU General Public License version 3 or (at your option) any later version.
    This program has absolutely no warranty.
    
    $ /usr/bin/ralib --version
    error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: unknown option character `-' in: --version
    Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib [-sactfqLT] [-] archive [...]
    

    Same for ar. If you're like me and had /usr/local/bin preceeding /usr/bin in $PATH, with the GNU tools in /usr/local/bin and the Xcode ones in /usr/bin, you can fix it with:

    cd /usr/local/bin
    mv ar gar
    ln -s /usr/bin/ar ar
    mv ranlib granlib
    ln -s /usr/bin/ranlib ranlib
    

提交回复
热议问题