在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题

Issues when cross compiling helloworld Windows executable on Linux with Clang / OLLVM

本文关键字:Windows helloworld 可执行文件 问题 交叉编译 OLLVM Linux Clang      更新时间:2023-10-16

我在Linux/Ubuntu系统上使用Clang/OLLVM编译Windows应用程序时遇到问题,我知道我"可以"为此使用其他工具(MinGW等(,但我想这样做,因为我想使用OLLVM提供的混淆。但是,我感觉Clang/LLVM在交叉编译(在Linux系统上编译Windows可执行文件(方面具有非常轻的文档,并且正确设置是某种黑魔法:-(。

我已经构建了这个项目:

https://github.com/qtfreet00/llvm-obfuscator

我已经做了以下工作,老实说,我不明白这些标志中的大多数实际上意味着什么,因为有些标志似乎完全没有记录:

https://nosubstance.me/post/coding-windows-cpp-on-linux/

而且我似乎已经走到了死胡同(区分大小写的问题包括使用<>而不是我修复的"等(,但现在我被困在似乎相当微不足道的事情上。当我尝试使用以下标志进行构建时:

/home/puss/dev/clang-llvm-build/bin/clang -isystem "/home/puss/dev/ewdk/program files/windows kits/10/include/10.0.19041.0/km/crt" -isystem "/home/puss/dev/ewdk-insensitive/program files/windows kits/10/include/10.0.19041.0/shared" -isystem "/home/puss/dev/ewdk-insensitive/program files/windows kits/10/include/10.0.19041.0/ucrt" -isystem "/home/puss/dev/ewdk-insensitive/program files/windows kits/10/include/10.0.19041.0/um" -isystem "/home/puss/dev/msf-http-stager/header" -target i386-pc-windows-msvc -x c++ -fsyntax-only -ferror-limit=64 -fms-compatibility-version=19 -Wno-everything -Wno-unknown-pragmas -U__clang__ -U__clang_version__ -U__clang_major__ -U__clang_minor__ -U__clang_patchlevel__ -fms-extensions -std=c++14 -mllvm -bcf -x c++ -c /tmp/hello.cpp -o hello.o

我的 hello.cpp 文件如下所示:

#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}

这是我得到的错误:

/tmp/hello.cpp:4:5: error: use of undeclared identifier 'std'
std::cout << "Hello World!";
^
1 error generated.

我在这里确实有iostream标头,编译器应该知道它,因为我使用指向它的-isystem标志指定了它:

/home/puss/dev/ewdk/program files/windows kits/10/include/10.0.19041.0/km/crt/iostream

似乎我的问题与此类似:

https://github.com/JuliaInterop/Cxx.jl/issues/114

关于这里发生了什么的任何想法?我还尝试拉出完全相同的 EWDK,如下所述:

https://nosubstance.me/post/coding-windows-cpp-on-linux/

但是当我在我的 hello.cpp 文件上运行它时:

#!/bin/sh
/home/william/dev/clang-llvm-build/bin/clang -x c++ 
--target=i386-pc-windows-msvc 
-fsyntax-only 
-ferror-limit=64 
-fms-compatibility-version=19 
-Wall 
-Wextra 
-Wno-unknown-pragmas 
-U__clang__ 
-U__clang_version__ 
-U__clang_major__ 
-U__clang_minor__ 
-U__clang_patchlevel__ 
-DWIN32 
-D_WINDOWS 
-DNDEBUG 
-D_MT 
-D_X86_=1 
-DNOMINMAX 
-D_WIN32_WINNT=0x0501 
-DWIN32_LEAN_AND_MEAN=1 
-D_CRT_SECURE_NO_WARNINGS=1 
-nostdinc 
-isystem '/home/william/dev/ewdk1703-insensitive/program files/windows kits/10/include/10.0.15063.0/shared' 
-isystem '/home/william/dev/ewdk1703-insensitive/program files/windows kits/10/include/10.0.15063.0/ucrt' 
-isystem '/home/william/dev/ewdk1703-insensitive/program files/windows kits/10/include/10.0.15063.0/um' 
-isystem '/home/william/dev/ewdk1703-insensitive/program files/microsoft visual studio 14.0/vc/include' 
-isystem '/home/william/dev/ewdk1703-insensitive/program files/windows kits/10/include/10.0.15063.0/km/crt' 
-c '/tmp/hello.cpp' -o 'hello.obj'

我还收到与"std"相关的错误:

/tmp/hello.cpp:4:5: error: use of undeclared identifier 'std'
std::cout << "Hello World!";
^
1 error generated.

奇怪的是,iostream.h标题在这里("km"(:

'/home/william/dev/ewdk1703-insensitive/program files/windows kits/10/include/10.0.15063.0/km/crt'

这似乎与内核驱动程序比用户模式应用程序更相关。

我终于能够解决这个问题,似乎这是一个使用的问题:

<iostream> vs <iostream.h>