Home > Software design >  A compilation error occurs when using clang in a Windows environment
A compilation error occurs when using clang in a Windows environment

Time:05-23

I compliation the code with Vscode. The clang -v:

clang version 14.0.3
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/mingw64/bin

You can see I get clang form msys.

The file I compliate use such header file:

#include <windows.h>
#include <windowsx.h>
#include <tchar.h>

#include <d2d1.h>

The task I use :

"args": [
            "-fdiagnostics-color=always",
            "C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22000.0\\um\\x86\\user32.lib",
            "C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22000.0\\um\\x86\\ole32.lib",
            "C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22000.0\\um\\x86\\d2d1.lib",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "-mwindows"
            ],

And the complier messages :

C:\msys64\mingw64\bin\clang-cpp.exe -fdiagnostics-color=always "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x86\user32.lib" "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x86\ole32.lib" "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x86\d2d1.lib" -g C:\Users\cookie\Desktop\GameEngineFromScratch\Platform\Windows\helloengine_d2d.cpp -o C:\Users\cookie\Desktop\GameEngineFromScratch\Platform\Windows\helloengine_d2d.exe -mwindows
clang-cpp: warning: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x86\user32.lib: 'linker' input unused in cpp mode [-Wunused-command-line-argument]
clang-cpp: warning: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x86\ole32.lib: 'linker' input unused in cpp mode [-Wunused-command-line-argument]
clang-cpp: warning: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x86\d2d1.lib: 'linker' input unused in cpp mode [-Wunused-command-line-argument]
clang-cpp: warning: argument unused during compilation: '-mwindows' [-Wunused-command-line-argument]

I got a executable file but when I run it my terminal give me an erro message Unable to run: The specified executable is not a valid application for this operating system platform

It look like I got a executable file for linux but not windows.How to solve this question.

CodePudding user response:

clang-cpp is the Clang preprocessor, not the C compiler. You should use clang for the C compiler front-end program.

  • Related