使用 Code::Blocks 编译时针对不同的 CPU - 理解错误
我正在使用 Code::Blocks 开发一个 C 应用程序,并且需要面向多个平台(32 位、64 位)。我的开发盒是64位的,所以我尝试在项目设置中检查编译器的i386(-march=i386)选项。现在,当我编译时,我得到:
mainc:1: error: CPU you selected does not support x86-64 instructions set
我不明白这条消息!通过指定 i386 不应该只是生成 x86 指令(而不是 -64)吗?另外,我的CPU是X86-64,为什么说我的CPU不支持这个?
我这样做的方式错了吗?是否有针对不同架构的正确方法?
I am developing a C app using Code::Blocks, and need to target multiple platforms (32 bit, 64 bit). My development box is 64 bit, so I tried to check the i386 (-march=i386) option for the compiler in the project settings. Now when I compile I get:
mainc:1: error: CPU you selected does not support x86-64 instruction set
I don't understand this message! By specifying i386 shouldn't it be just generating x86 instructions (not -64)? Beside, my CPU is X86-64 so why say my cpu doesn't support this?
Am I doing this the wrong way? Is there a RIGHT way to target different architectures?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在这里区分几件事:
-march
开关)。这决定了假设的处理器世代,这决定了可以使用哪些指令来生成代码。并非每个平台和架构的组合都是有效的(这正是您的问题:假设使用了 25 年的 386 处理器意味着它不可能在 AMD64 模式下运行)。-msse
系列,可以进一步启用/禁用指令。您没有指定“Windows”或“Linux”或其他任何内容,因此很难对您的问题给出准确答案,但我们假设您可能使用例如 MingW-w64。该编译器允许您创建 32 位和 64 位代码,具体取决于您告诉它做什么。显然,如果你告诉它以 64 模式(默认!)生成代码,那么 i386 不是一个好的选择。如果你给它
-m32
作为命令行选项,它将生成 32 位代码,并且它会工作。如果您准确地告诉您使用的编译器,可能会有助于找到更具体的答案。例如,Code::Blocks(可选)随 Windows 上的 TDM 4.5.1 版本一起提供,但使用其他操作系统下的任何内容。
You must distinguish several things here:
-march
switch). This decides what processor generation is assumed, which determines what instructions can be used in generating code. Not every combination of platform and architecture is valid (this is your very problem: assuming a 25 year old 386 processor means that it cannot possibly run in AMD64 mode).-msse
family which further enable/disable instructions.You did not specify "Windows" or "Linux" or anything else, so it is hard to give an exact answer to what your problem is, but let's assume you might be using for example MingW-w64. This compiler lets you create both 32 and 64 bit code, depending on what you tell it to do. Obviously, if you tell it to generate code in 64 mode (the default!), then i386 is not a good choice. If you give it
-m32
as a commandline option, it will generate 32bit code, and it will work.It may help finding a more concrete answer if you tell exactly what compiler you use. Code::Blocks comes (optionally) with the TDM 4.5.1 build on Windows, for example, but uses whatever is there under other operating systems.