开发者

Native toolchain issue on Macos 10.6.8 (Snow Leopard)

开发者 https://www.devze.com 2023-04-11 21:35 出处:网络
Below is the description of the issue. I marked it all as a code to avoid the implicit formatting that StackOverflow does.

Below is the description of the issue. I marked it all as a code to avoid the implicit formatting that StackOverflow does. That is pretty annoying to have to deal with the Wiki-like markup language when I know exactly myself how I want to format my question.

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 wa开发者_开发百科rning 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.


You are not using the Xcode native ar. The OS X native ar is a BSD-derived one, not GNU ar. Try which ar to find out where you are picking it up from. The Xcode-supplied one should be at /usr/bin/ar.


The GNU ar is not compatible with the native Macos ld The native Macos ar is this one actually :

/usr/bin/ld -v @(#)PROGRAM:ld PROJECT:ld64-97.17 llvm version 2.9svn, from Apple Clang 1.7 (build 77)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号