机器类型(C++ 库):i386 与 x86_64 [英] machine type (C++ librairies) : i386 vs x86_64

查看:28
本文介绍了机器类型(C++ 库):i386 与 x86_64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对不同的机器架构(32 位、64 位...)知之甚少.正因为如此,我经常在不同的机器上使用 C++ 库时遇到困难,被烦人的架构的未定义符号......"所困扰.

I have little understanding about the different machine architectures (32bits , 64bits,...). And because of that, I often have hard time when using C++ libraries on different machines, being stuck with the annoying "undefined symbols for architecture...".

如果有人能向我解释为什么当我在同一台机器(一台安装了 Mountain Lion 操作系统的 2 岁 mac)上使用以下命令时会得到如此令人困惑的答案,我会非常高兴.man uname 表示

I would be really happy if someone can explain to me why I get such confusing answers when I use the following commands on the same machine (a 2 years old mac with mountain Lion OS) . the man uname indicates

-m 打印机器硬件名称.

-m print the machine hardware name.

-p 打印机器处理器架构名称.

-p print the machine processor architecture name.

  • 乍一看,我会说 -p 更相关.所以我运行 uname -p 并得到:
  • i386(如果我没记错的话,这意味着 32 位).

    i386 (which means 32bits If I am not wrong).

    • 但是对于我在同一台机器上编译的库,运行 lipo -info lib_test.a 返回:

    输入文件 lib_test.a 不是胖文件

    非胖文件:lib_test.a 是架构:x86_64(如果我没记错的话就是64位)

    Non-fat file: lib_test.a is architecture: x86_64 (which means 64bits If I am not wrong)

    • 然而,后者与 uname -m 的返回更加一致,即
    • The Latter is however more coherent with the return of uname -m which is

    x86_64

    推荐答案

    这是一个 Mac OS X 奇怪的地方.OS X for Intel 所搭载的所有硬件都是 64 位的,操作系统也是如此——但是,它可以强制在 32 位模式下运行.它能够执行 64 位和 32 位二进制文​​件,除非在 32 位模式下运行.

    It's a Mac OS X oddity. All hardware that OS X for Intel has shipped on has been 64-bit and so has the operating system - however, it can be force run in 32-bit-only mode. It's capable of executing 64-bit and 32-bit binaries, unless run in 32-bit mode.

    此平台上交付的大多数二进制文件(.dylib 和可执行文件)都是胖"二进制文件,这意味着它们包含 32 位 Intel 二进制文件和 64 位 Intel 二进制文件,有时还包含其他架构(Power PC)的二进制文件成一个文件.系统会自动加载二进制文件中最合适的部分.

    Most binaries (.dylib and executables) delivered on this platform are "fat" binaries, means they contain both a 32-bit Intel binary and a 64-bit Intel binary, and sometimes binaries for other architectures (Power PC) combined into one file. The system will automatically load the most suitable part of the binary.

    因为底层编译器通常需要运行不同的flag来为不同的架构生成二进制文件,甚至平台#defines也不同,使得编译器在预处理后看到的源代码不同,二进制文件需要每次编译一次平台分开,然后结合使用 lipo 实用程序.XCode 可以代表您自动执行此过程.

    Because the underlying compiler usually needs to run with different flags to generate binaries for different architectures, and even the platform #defines are different, making the compiler see different source code after pre-processing, the binary needs to be compiled once per platform separately and then combined using lipo utility. XCode can automate this process on your behalf.

    虽然系统能够运行不同的二进制文件,包括 32 位和 64 位,但它们的执行模型是不同的,并且它们不能组合在同一个进程地址空间中.因此,如果您将一个库设为 64 位,而另一个库设为 32 位,则不能一起使用.

    While the system is capable of running different binaries, both 32-bit and 64-bit, their execution model is different and they cannot be combined in the same process address space. So if you have one library as 64-bit only and other as 32-bit only, you cannot use them together.

    这篇关于机器类型(C++ 库):i386 与 x86_64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆