繁体   English   中英

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

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

我正在尝试将文件编译为 x86 但我不断收到此错误: (Main.obj: fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86')

我相应地设置了我的构建任务:

{
    "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
            }
        }
    ]
}

控制台 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'

尽管指定了 WIN32 选项,编译器仍将 Main.obj 识别为 x64 模块。

编译器版本设置为 x64。 我将 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM