从WSL Ubuntu交叉编译到Win32

时间:2019-07-30 19:55:28

标签: c++ cmake clang cross-compiling windows-subsystem-for-linux

我正在写很多跨平台的C ++,并且试图统一我在平台之间的构建过程(目前主要针对Windows和Mac,将来可能会移动。)除了我们的常规CI生成之外,我们它们是作为大型C ++项目构建的一部分从源代码构建的,因此具有相当复杂的工具链。

现在,我的代码在Windows上使用CMake干净地编译,以生成Visual Studio项目,然后使用clang-cl进行编译。同样,我们使用CMake生成忍者项目,然后使用clang进行编译。

我们是Windows商店,我想利用WSL来建立交叉编译,这应该允许我们使用相同的ninja项目来定位两个受支持的平台并在将来进行修改。

我能够使用wsl托管的bash终端中的clang成功编译一个简单的hello world exe程序。为此,我不得不为clang提供大量选项,并将大量Win10 SDK库移至我的构建环境中,以便clang进行构建和链接。

这是我运行以成功生成helloworld.exe的两个命令: 编译:

clang -target i686-pc-win32 -fms-compatibility-version=19 -fms-extensions -fdelayed-template-parsing -fexceptions -mthread-model posix -fno-threadsafe-statics -Wno-msvc-not-found -DWIN32 -D_WIN32 -D_MT -D_DLL -Xclang -disable-llvm-verifier -Xclang '--dependent-lib=msvcrt' -Xclang '--dependent-lib=ucrt' -Xclang '--dependent-lib=oldnames' -Xclang '--dependent-lib=vcruntime' -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -U__GNUC__ -U__gnu_linux__ -U__GNUC_MINOR__ -U__GNUC_PATCHLEVEL__ -U__GNUC_STDC_INLINE__ -I/mnt/d/source/windeps/LLVM/include -I/mnt/d/source/windeps/MSVC/14.22.27905/include -I/mnt/d/source/windeps/ucrt -I/mnt/d/source/windeps/shared  -I/mnt/d/source/windeps/winrt -c hello.cc -o hello.o

链接:

clang -fuse-ld=lld-link.exe -target i686-pc-win32 -Wl,-machine:x86 -fmsc-version=1923 -o hello.exe hello.o -L/mnt/d/source/windeps/MSVC/14.22.27905/lib/x86/msvcrt.lib -nostdlib -lmsvcrt -Wno-msvc-not-found

自然地,我试图通过我的CMake工具链表达这第一个命令:

    add_compile_options(
        -W
        -Wall
        -std=c++17
        -stdlib=libc++
        -fcoroutines-ts
        -fms-extensions
        -fdelayed-template-parsing
        -fexceptions
        -fdeclspec
        -mthread-model posix
        -fno-threadsafe-statics
        -Wno-msvc-not-found
        -DWIN32
        -D_WIN32
        -D_MT
        -D_DLL
        -Xclang
        -disable-llvm-verifier
        # These are commented out currently, but I have linked them to the proper CMakeList
        # -Xclang '--dependent-lib=msvcrt'
        # -Xclang '--dependent-lib=ucrt'
        # -Xclang '--dependent-lib=oldnames'
        # -Xclang '--dependent-lib=vcruntime'
        -D_CRT_SECURE_NO_WARNINGS
        -D_CRT_NONSTDC_NO_DEPRECATE
        -U__GNUC__
        -U__gnu_linux__
        -U__GNUC_MINOR__
        -U__GNUC_PATCHLEVEL__
        -U__GNUC_STDC_INLINE__
        -I/mnt/d/source/windeps/LLVM/include
        -I/mnt/d/source/windeps/MSVC/14.22.27905/include
        -I/mnt/d/source/windeps/um
        -I/mnt/d/source/windeps/ucrt
        -I/mnt/d/source/windeps/shared
        -I/mnt/d/source/windeps/winrt
    )

当我们的文件之一(event_logger.cpp)执行#include <array>时,这将在ucrt库中引发错误。

In file included from src/client/services/src/event_logger.cpp:10:
In file included from /mnt/d/source/windeps/MSVC/14.22.27905/include/array:6:
In file included from /mnt/d/source/windeps/MSVC/14.22.27905/include/algorithm:6:
In file included from /mnt/d/source/windeps/MSVC/14.22.27905/include/xmemory:8:
In file included from /mnt/d/source/windeps/MSVC/14.22.27905/include/limits:8:
In file included from /mnt/d/source/windeps/MSVC/14.22.27905/include/cwchar:8:
In file included from /mnt/d/source/windeps/MSVC/14.22.27905/include/cstdio:8:
In file included from /mnt/d/source/windeps/ucrt/stdio.h:13:
/mnt/d/source/windeps/ucrt/corecrt_wstdio.h:581:9: error: use of undeclared identifier '__crt_va_end'
        __crt_va_end(_ArgList);
        ^
/mnt/d/source/windeps/ucrt/corecrt_wstdio.h:597:9: error: use of undeclared identifier '__crt_va_start_a'
        __crt_va_start(_ArgList, _Locale);
        ^
/mnt/d/source/windeps/MSVC/14.22.27905/include/vadefs.h:156:99: note: expanded from macro '__crt_va_start'
    #define __crt_va_start(ap, x) ((void)(__vcrt_assert_va_start_is_not_reference<decltype(x)>(), __crt_va_start_a(ap, x)))

由于这种行为,我怀疑也许我们没有使用-stdlib标志所指示的libc ++。我也不确定如何纠正此问题,因为这似乎是一个较新的过程,并且还没有大量的文档。任何建议表示赞赏。

0 个答案:

没有答案