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

查看:199
本文介绍了机器类型(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 OS的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,我得到了:
    • At a first look, I would say that -p is more relevant. So I run uname -p and I get:
    • i386 (如果我没记错,则表示32位).

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

      • 但是对于在同一台计算机上编译的库,运行lipo -info lib_test.a会返回:
      • However for a library that I compiled on the same machine, running lipo -info lib_test.a returns:

      输入文件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附带的所有硬件都是64位的,操作系统也是如此-但是,可以强制将其强制运行在仅32位的模式下.除非以32位模式运行,否则它能够执行64位和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.

      由于底层编译器通常需要运行不同的标志才能生成用于不同体系结构的二进制文件,甚至平台的#define也不同,从而使编译器在预处理后看到不同的源代码,因此二进制文件每次需要编译一次平台分开使用,然后使用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天全站免登陆