繁体   English   中英

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

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

我在 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 header,编译器应该知道它,因为我使用指向它的 -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 header 在这里(“km”):

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

这似乎与 Kernel 驱动程序有关,而不是用户模式应用程序。

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

<iostream> vs <iostream.h>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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