简体   繁体   English

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

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

I am having issues compiling a Windows application with Clang / OLLVM on a Linux/Ubuntu system, I know I "could" use other tools for this (MinGW etc...) but I want to do it this way because I want to use obfuscation which is provided by OLLVM.我在 Linux/Ubuntu 系统上使用 Clang / OLLVM 编译 Windows 应用程序时遇到问题,我知道我“可以”为此使用其他工具(MinGW 等......)但我想这样做是因为我想使用OLLVM 提供的混淆。 However I have the feeling that Clang/LLVM has very light documentation in regards to cross-compilation (compiling Windows executables on a Linux system) and that setting things up correctly is some kind of black magic:-(.但是我觉得 Clang/LLVM 在交叉编译方面的文档非常简单(在 Linux 系统上编译 Windows 可执行文件),并且正确设置是某种黑魔法:-(。

I have built this project:我已经建立了这个项目:

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

And I have done the following and to be very honest, I do not understand what most of these flags actually mean, since some appear to be completely un-documented:而且我已经做了以下事情,老实说,我不明白这些标志中的大多数实际上是什么意思,因为有些似乎完全没有记录:

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

And I seem to have reached a dead-end (had issues with case-sensitivity includes using <> instead of "" which I fixed etc...) but now I am stuck on something which appears fairly trivial to solve.而且我似乎已经走到了尽头(区分大小写的问题包括使用<>而不是我修复的“”等......)但现在我被困在一些看起来相当容易解决的问题上。 When I try to build using the following flags:当我尝试使用以下标志进行构建时:

/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

my hello.cpp file looks like this:我的 hello.cpp 文件如下所示:

#include <iostream>

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

Here is the error I am getting:这是我得到的错误:

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

I do have the iostream header here, which should be known to the compiler because I specified it using a -isystem flag pointing to it:我在这里确实有 iostream header,编译器应该知道它,因为我使用指向它的 -isystem 标志指定了它:

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

As it seems my issue is similar to this one:看来我的问题与此类似:

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

Any ideas as to what is going on here?关于这里发生了什么的任何想法? I also tried pulling the exact same EWDK as described here:我还尝试提取与此处描述的完全相同的 EWDK:

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

but when I run this on my hello.cpp file:但是当我在我的 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'

I also get errors relating to 'std':我还收到与“std”相关的错误:

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

On weird thing though is that the iostream.h header is in here ("km"):奇怪的是, iostream.h header 在这里(“km”):

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

Which seems to relate more to Kernel drivers than user-mode applications.这似乎与 Kernel 驱动程序有关,而不是用户模式应用程序。

I was finally able to fix the issue, it seems that it was an issue of using:我终于能够解决这个问题,似乎这是使用的问题:

<iostream> vs <iostream.h>

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

相关问题 在 linux 上交叉编译 windows 时出现类型定义冲突 - Conflicting typedefs when cross compiling for windows on linux 在Windows上交叉编译Linux(链接器输出文件不会在linux上作为可执行文件运行并且具有未定义的符号) - Cross compiling for Linux on Windows (linker output file won't run as executable on linux and has undefined symbols) 在Linux上交叉编译Windows应用程序时如何链接到Winsock? - How to link to Winsock when cross-compiling a Windows app on Linux? Linux 上 Windows 的交叉编译提升 - Cross-compiling boost for Windows on Linux 提升未定义的引用,将Linux交叉编译到Windows - Boost undefined references cross compiling linux to windows 在Windows上使用clang编译CUDA时的重新定义 - Redefinitions when compiling CUDA with clang on Windows 在Linux上与Eclipse交叉编译,在Windows上与Eclipse交叉编译? - cross compiling with Eclipse on linux and eclipse on windows? 在Linux for Windows上交叉编译boost光纤库 - Cross compiling boost fiber library on Linux for Windows 在Linux for Windows上交叉编译Qt5 - Cross Compiling Qt5 on Linux for Windows 当交叉编译(Linux 到 Windows)Vulkan 加载器时,有许多对 Vulkan 对象的未定义引用 - When Cross Compiling (Linux to Windows) The Vulkan Loader There Are Many Undefined References to Vulkan Objects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM