简体   繁体   English

为什么在尝试使用 MSVC 编译 32 位代码时出现错误?

[英]Why am I getting an error when trying to compile 32-bit code with MSVC?

I'm trying to compile a file as x86 but I keep getting this error: (Main.obj: fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86')我正在尝试将文件编译为 x86 但我不断收到此错误: (Main.obj: fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86')

I set up my build task accordingly as such:我相应地设置了我的构建任务:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: cl.exe build active file",
            "command": "CL",
            "args": [
                "/D WIN32",
                "${file}",
                "\"C:\\Users\\Axair\\Desktop\\VScode\\OpenGL\\GLFW\\lib-vc2022\\glfw3.lib\"", // 32 bit library
                "/link",
                "/MACHINE:X86"
            ],
            "presentation": {
                "showReuseMessage": false,
                "clear": true,
                "close": false
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Console output looks like this:控制台 output 如下所示:

C:\Users\Axair\Desktop\VScode\OpenGL>cl /D WIN32 "C:\Users\Axair\Desktop\VScode\OpenGL\Main.cpp" "C:\Users\Axair\Desktop\VScode\OpenGL\GLFW\lib-vc2022\glfw3.lib" /link /MACHINE:X86
Microsoft (R) C/C++ Optimizing Compiler Version 19.32.31332 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Main.cpp
Microsoft (R) Incremental Linker Version 14.32.31332.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Main.exe
/MACHINE:X86
Main.obj
C:\Users\Axair\Desktop\VScode\OpenGL\GLFW\lib-vc2022\glfw3.lib
Main.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'

The compiler keeps recognizing Main.obj as an x64 module despite the specified WIN32 option.尽管指定了 WIN32 选项,编译器仍将 Main.obj 识别为 x64 模块。

The compiler version was set to x64.编译器版本设置为 x64。 I changed my PATH variable to point to the right version of the compiler, in my case -> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x86我将 PATH 变量更改为指向正确版本的编译器,在我的情况下 -> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x86

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在尝试编译时遇到此编译错误? - Why am i getting this compile error when i try to compile? 如何将混合(asm,C ++)源代码编译为32位程序? - How can I compile a hybrid (asm, C++) source code into a 32-bit program? 使用Mingw-w64使用-m32选项(32位代码)进行编译时出错 - Error when compiling with -m32 option (32-bit code) using Mingw-w64 为什么在 C++ 中编译 64 位时会出现 32 位溢出? - Why do I get a 32-bit overflow when compiling in 64-bit in C++? 我试图在Visual Studio 2010编译c ++代码,我收到链接器错误 - I am trying to compile a c++ code at visual studio 2010 and i am getting a linker error 为什么会出现此模板编译错误? - Why am i getting this template compile error? 为什么“ long *”和“ int *”在32位代码中不兼容? - Why are “long *” and “int *” not compatible in 32-bit code? 为什么我会收到错误:当我尝试编译C ++代码时,在Eclipse中初始化'Item :: Item(int)'[-fpermissive]的参数1? - Why am I getting error: initializing argument 1 of 'Item::Item(int)' [-fpermissive] in Eclipse when I try to compile my C++ code? 为什么在 Boost zip 迭代器上使用 C++17 并行执行算法时,MSVC 会出现错误? - Why am I getting an error with MSVC when using a C++17 parallel execution algorithm on Boost zip iterators? 在64位计算机上编译32位代码时,应如何处理“从'void *'到'int'的转换会失去精度”? - How should I handle “cast from ‘void*’ to ‘int’ loses precision” when compiling 32-bit code on 64-bit machine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM