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

Viewed 93

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')

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:

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.

1 Answers

The compiler version was set to 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

Related