Macos 10.6.8 (Snow Leopard) 上的本机工具链问题

发布于 2024-12-09 10:03:54 字数 1324 浏览 0 评论 0原文

下面是问题的描述。 我将其全部标记为代码,以避免 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.

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彻夜缠绵 2024-12-16 10:03:54

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

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.

七色彩虹 2024-12-16 10:03:54

GNU ar 与本机 Macos ld 不兼容
本机 Macos ar 实际上是这个:

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

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文