在Windows中使用GCC或Clang强制LP64数据模型 [英] Force LP64 data model with GCC or Clang in Windows

查看:56
本文介绍了在Windows中使用GCC或Clang强制LP64数据模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在针对Windows时强制GCC和/或Clang编译器使用LP64数据模型(忽略Windows使用LLP64数据模型)?

Is there a way to force GCC and/or Clang compiler to use LP64 data model when targeting Windows (ignoring that Windows use LLP64 data model)?

推荐答案

否,因为请求的功能不起作用

您正在以Windows为目标",大概意味着您希望编译器生成将以常规方式在Windows下运行的代码.为此,该程序必须调用Windows API中的函数.实际上有三种Windows API版本:win16,win32和win64.由于您要使用64位指针("LP64"中的"P64"),因此唯一可能的目标是win64.

No, because the requested capability would not work

You are "targeting Windows", presumably meaning you want the compiler to produce code that will run under Windows in the usual way. In order to do that, the program must invoke functions in the Windows API. There are effectively three versions of the Windows API: win16, win32, and win64. Since you want 64-bit pointers (the "P64" in "LP64"), the only possible target is win64.

要调用win64函数,必须包含 windows.h .该头文件使用 long .如果有编译器要求坚持将 long 视为64位整数(LP64)而不是32位(LLP64),则编译器对如何调用函数和布置数据的理解使用 long 的结构将是错误的;结果程序将无法正确运行.

In order to call a win64 function, you must include windows.h. That header file uses long. If there were a compiler switch to insist that long be treated as a 64-bit integer (LP64) rather than 32-bit (LLP64), then the compiler's understanding of how to call functions and lay out data structures that use long would be wrong; the resulting program would not run correctly.

相同的问题适用于标准C和C ++库.如果链接到现有的已编译库(通常),则对该库的调用将不起作用(因为它将使用LLP64).如果要使用假想的开关强制LP64从源代码构建一个,则对Windows API的调用将失败.

The same problem applies to the standard C and C++ libraries. If you link to an existing compiled library (as is typical), the calls into it won't work (since it will use LLP64). If you were to build one from source using a hypothetical switch to force LP64, its calls into the Windows API would fail.

Cygwin 使用LP64并生成在Windows上运行的二进制文件.尽管我已经写了上面的内容,但是这是可能的,因为Cygwin DLL充当Cygwin LP64环境和本机win64 LLP64环境之间的桥梁.假设您有最初为win32编写的代码,现在想利用64位地址空间而不进行代码更改或代码更改最少,那么我怀疑这是最简单的方法.但是我应该承认,我从来没有以这种方式使用过Cygwin,所以可能会有我不知道的问题.

Cygwin uses LP64 and produces binaries that run on Windows. That is possible, despite what I wrote above, because the Cygwin DLL acts as a bridge between the Cygwin LP64 environment and the native win64 LLP64 environment. Assuming you have code originally written for win32 that you now want to take advantage of a 64-bit address space with no or minimal code changes, I suspect this is the easiest path. But I should acknowledge that I've never used Cygwin in quite this way so there might be problems I am not aware of.

这篇关于在Windows中使用GCC或Clang强制LP64数据模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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