简体   繁体   中英

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. 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:-(.

I have built this project:

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/

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:

#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:

/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

Any ideas as to what is going on here? I also tried pulling the exact same EWDK as described here:

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

but when I run this on my hello.cpp file:

#!/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':

/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"):

'/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.

I was finally able to fix the issue, it seems that it was an issue of using:

<iostream> vs <iostream.h>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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