【问题标题】:Native toolchain issue on Macos 10.6.8 (Snow Leopard)Macos 10.6.8 (Snow Leopard) 上的本机工具链问题
【发布时间】:2011-12-04 22:23:38
【问题描述】:

以下是问题的描述。 我将其全部标记为代码以避免 StackOverflow 所做的隐式格式化。 不得不处理类似 Wiki 的标记语言,这很烦人 当我确切地知道我想如何格式化我的问题时。

I am dealing with a weird toolchain issue on Macos.
Here is what is going on :

 $ cat gmpz.c

    char foo ();

    int main ()
    {
    return foo();
    }

$ cat libmy.c

    char foo()
    {
    return 0;
    }

I run these commands :

$ gcc -c libmy.c 
$ gcc gmpz.c libmy.o
$ file ./a.out
./a.out: Mach-O 64-bit executable x86_64

So far it is all good. But here is the problem :

$ ar qv libmy.a libmy.o
ar: creating libmy.a
a - libmy.o

$ gcc gmpz.c libmy.a
ld: warning: in libmy.a, file was built for unsupported file format which
is not the architecture being linked (x86_64)
Undefined symbols:
  "_foo", referenced from:
      _main in ccpwg2Ju.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Adding "-arch i386" to gcc flags doesn't change the final warning and the
unresolved symbol error (except that the name of the architecture becomes different).

The above example works fine on Linux. It seems like the basic ar
functionality is broken on my system.
I have Xcode 3.2.6

$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)

$ ar --version
GNU ar (GNU Binutils) 2.21

Any ideas on resolving this issue are greatly appreciated.

【问题讨论】:

    标签: gcc osx-snow-leopard binutils unix-ar


    【解决方案1】:

    您没有使用 Xcode 原生 ar。 OS X 本机 ar 是 BSD 派生的,而不是 GNU ar。尝试which ar 找出您从哪里获取它。 Xcode 提供的地址应该是/usr/bin/ar

    【讨论】:

      【解决方案2】:

      GNU ar 与原生 Macos ld 不兼容 原生的 Macos ar 实际上就是这个:

      /usr/bin/ld -v @(#)程序:ld 项目:ld64-97.17 llvm 版本 2.9svn,来自 Apple Clang 1.7(内部版本 77)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-12
        • 2010-11-04
        • 1970-01-01
        • 2010-12-30
        • 2011-07-13
        • 1970-01-01
        相关资源
        最近更新 更多