簡體   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