如何在32位或64位环境中以编程方式启动程序? [英] How can I programmatically start a program in the 32 bits or 64 bits environment?

查看:113
本文介绍了如何在32位或64位环境中以编程方式启动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以同时在32位和64位上运行的二进制文件,该文件可用于摆弄动态捆绑包.但是,默认情况下,它运行在64位环境中.因此,如果我碰到一个仅32位的捆绑软件,则dlopen失败.

I have a binary that can be run in both 32 and 64 bits, that loads dynamic bundles for fiddling purposes. However, by default it runs on the 64 bits environment; so if I hit a 32-bits only bundle, dlopen fails.

事先检查一下很容易,所以我真正需要的是选择以32位还是64位启动它的方法.我如何以编程方式做到这一点?我对雪豹可能支持的任何事物持开放态度.

It's easy to check for this beforehand, so all I really need is a way to choose whether to launch it in 32 bits or 64 bits. How can I programmatically do that? I'm open to anything Snow Leopard might support.

推荐答案

除了@GWW编写的内容之外,如果您真的想以编程方式执行此操作,则可以使用

In addition to what @GWW wrote, if you really want to do this programmatically, you can use posix_spawnattr_setbinpref_np to set the preferred CPU type and then use posix_spawn.

CPU类型由cpu_type_t指定,我相信它是在#include <mach/machine.h>中定义的.但是包含#include <mach-o/arch.h>可能更安全.请参见 arch(3)联机帮助页.

The CPU type is specified by cpu_type_t, which I believe is defined in #include <mach/machine.h>. But it may be safer to include #include <mach-o/arch.h>. See arch (3) manpage.

这篇关于如何在32位或64位环境中以编程方式启动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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