【问题标题】:How can I programmatically start a program in the 32 bits or 64 bits environment?如何以编程方式在 32 位或 64 位环境中启动程序?
【发布时间】:2011-03-11 04:29:42
【问题描述】:

我有一个可以在 32 位和 64 位中运行的二进制文件,它可以加载动态捆绑包以进行摆弄。但是,默认情况下它在 64 位环境下运行;因此,如果我遇到仅 32 位的捆绑包,dlopen 会失败。

事先检查这一点很容易,所以我真正需要的是一种方法来选择是以 32 位还是 64 位启动它。我怎样才能以编程方式做到这一点?我对 Snow Leopard 可能支持的任何内容持开放态度。

【问题讨论】:

    标签: macos executable


    【解决方案1】:

    除了@GWW 写的,如果你真的想以编程方式进行,可以使用posix_spawnattr_setbinpref_np 设置首选CPU 类型,然后使用posix_spawn

    CPU 类型由cpu_type_t 指定,我相信它在#include <mach/machine.h> 中定义。但包含#include <mach-o/arch.h> 可能更安全。见arch (3) manpage

    【讨论】:

    • 它是用<mach-o/fat.h> 定义的(在#include 图中的某个位置),我已经包含了它。
    【解决方案2】:

    这对我在 32 位/64 位中启动 python 很有用

    arch -i386 python
    Python 2.7 (r27:82500, Nov 10 2010, 22:46:43) 
    [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.maxint
    2147483647
    
    arch -x86_64 python
    Python 2.7 (r27:82500, Nov 10 2010, 22:46:43) 
    [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.maxint
    9223372036854775807
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-08
      • 2013-03-11
      • 1970-01-01
      • 2012-01-19
      • 1970-01-01
      • 2011-01-01
      • 1970-01-01
      • 2013-01-04
      相关资源
      最近更新 更多