How to cross compile from linux to windows #17062
-
I try to build libbacktrace for mingw from linux, I am using the mxe environment. I have created the triplet file:
with mxe-conf.cmake[root:/usr/src/mxe] # cat usr/x86_64-w64-mingw32.shared.posix/share/cmake/mxe-conf.cmake # This file is part of MXE. See LICENSE.md for licensing information. # https://cmake.org/cmake/help/latest # Can't set `cmake_minimum_required` or `cmake_policy` in toolchain # since toolchain is read before CMakeLists.txt # See `target-cmake.in` for CMAKE_POLICY_DEFAULT_CMPNNNN # Check if we are using mxe supplied version # - toolchain is included multiple times so set a guard in # environment to suppress duplicate messages if(NOT ${CMAKE_COMMAND} STREQUAL /usr/src/mxe/usr/x86_64-pc-linux-gnu/bin/cmake AND NOT DEFINED ENV{_MXE_CMAKE_TOOLCHAIN_INCLUDED}) message(WARNING " ** Warning: direct use of toolchain file is deprecated ** Please use prefixed wrapper script instead: x86_64-w64-mingw32.shared.posix-cmake [options] - uses mxe supplied cmake version 3.19.2 - loads toolchain - loads common run results - sets various policy defaults ") set(ENV{_MXE_CMAKE_TOOLCHAIN_INCLUDED} TRUE) endif() # Use CACHE variables to allow user setting with `-D` # Use CACHE FORCE in rare cases of misconfigured CMakeLists.txt # - e.g include(FindPkgConfig) # https://github.com/mxe/mxe/issues/1023 # - projects may still set these in which case FORCE doesn't have # any advantage, just causes inconvenience # https://github.com/mxe/mxe/pull/1621#discussion_r106937505 # Use normal variables expected to be set by toolchain/system # - projects should test for these values and not try to override ## General configuration set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR x86_64 CACHE STRING "System Processor") set(MSYS 1) set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) # Workaround for https://www.cmake.org/Bug/view.php?id=14075 set(CMAKE_CROSS_COMPILING ON) ## Library config set(BUILD_SHARED_LIBS ON CACHE BOOL "BUILD_SHARED_LIBS") set(BUILD_STATIC_LIBS OFF CACHE BOOL "BUILD_STATIC_LIBS") set(BUILD_SHARED ON CACHE BOOL "BUILD_SHARED") set(BUILD_STATIC OFF CACHE BOOL "BUILD_STATIC") set(LIBTYPE SHARED) ## Paths etc. # These MODEs shouldn't be changed by users, we only want headers/libs # from cross-build and "never" want binaries. We do, however, want # `*-config` scripts but there's no way to instruct cmake to do that. # # The best solution may be to whitelist utilities # https://github.com/mxe/mxe/issues/1667 # and symlink them to an additional root path, changing PROGRAM to ONLY set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) # Allow user to specify list of locations to search set(CMAKE_FIND_ROOT_PATH /usr/src/mxe/usr/x86_64-w64-mingw32.shared.posix CACHE PATH "List of root paths to search on the filesystem") set(CMAKE_PREFIX_PATH /usr/src/mxe/usr/x86_64-w64-mingw32.shared.posix CACHE PATH "List of directories specifying installation prefixes to be searched") set(CMAKE_INSTALL_PREFIX /usr/src/mxe/usr/x86_64-w64-mingw32.shared.posix CACHE PATH "Installation Prefix") # For custom mxe FindPackage scripts set(CMAKE_MODULE_PATH "/usr/src/mxe/usr/share/cmake/modules" ${CMAKE_MODULE_PATH}) # projects (mis)use `-isystem` to silence warnings from 3rd-party # source (among other things). gcc6 introduces changes to search # order which breaks this usage. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129 # https://gitlab.kitware.com/cmake/cmake/issues/16291 # https://gitlab.kitware.com/cmake/cmake/issues/16919 set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES /usr/src/mxe/usr/x86_64-w64-mingw32.shared.posix/include) set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES /usr/src/mxe/usr/x86_64-w64-mingw32.shared.posix/include) ## Programs set(CMAKE_C_COMPILER /usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-gcc) set(CMAKE_CXX_COMPILER /usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-g++) set(CMAKE_Fortran_COMPILER /usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-gfortran) set(CMAKE_RC_COMPILER /usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-windres) # CMAKE_RC_COMPILE_OBJECT is defined in: # /share/cmake-X.Y/Modules/Platform/Windows-windres.cmake set(CPACK_NSIS_EXECUTABLE x86_64-w64-mingw32.shared.posix-makensis) ## Individual package configuration file(GLOB mxe_cmake_files "/usr/src/mxe/usr/x86_64-w64-mingw32.shared.posix/share/cmake/mxe-conf.d/*.cmake" ) foreach(mxe_cmake_file ${mxe_cmake_files}) include(${mxe_cmake_file}) endforeach() set(CMAKE_CROSSCOMPILING_EMULATOR "/usr/bin/wine") and
config-x64-linux-windows-static-dbg-err.log:
with config.logThis file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by package-unused configure version-unused, which was generated by GNU Autoconf 2.69. Invocation command line was $ ./../src/876b545088-bf2d416700.clean/configure --host=mingw32 --disable-silent-rules --verbose --disable-shared --enable-static --prefix=/builds/leander.schulten/Lichtsteuerung/vcpkg_installed/x64-linux-windows-static/debug --bindir=${prefix}/../tools/libbacktrace/debug/bin --sbindir=${prefix}/../tools/libbacktrace/debug/sbin --includedir=${prefix}/../include --datarootdir=${prefix}/share/libbacktrace ## --------- ## ## Platform. ## ## --------- ## hostname = runner-cdb9c124-project-10017-concurrent-0 uname -m = x86_64 uname -r = 4.4.0-203-generic uname -s = Linux uname -v = #235-Ubuntu SMP Tue Feb 2 02:49:08 UTC 2021 /usr/bin/uname -p = unknown /bin/uname -X = unknown /bin/arch = unknown /usr/bin/arch -k = unknown /usr/convex/getsysinfo = unknown /usr/bin/hostinfo = unknown /bin/machine = unknown /usr/bin/oslevel = unknown /bin/universe = unknown PATH: /usr/local/sbin PATH: /usr/local/bin PATH: /usr/sbin PATH: /usr/bin PATH: /sbin PATH: /bin PATH: /usr/src/mxe/usr/bin PATH: /builds/leander.schulten/Lichtsteuerung/vcpkg/downloads/tools/ninja-1.10.1-linux ## ----------- ## ## Core tests. ## ## ----------- ## configure:2379: checking build system type configure:2393: result: x86_64-pc-linux-gnu configure:2413: checking host system type configure:2426: result: i686-pc-mingw32 configure:2446: checking target system type configure:2459: result: i686-pc-mingw32 configure:2499: checking for mingw32-gcc configure:2526: result: /usr/bin/gcc configure:2795: checking for C compiler version configure:2804: /usr/bin/gcc --version >&5 gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. configure:2815: $? = 0 configure:2804: /usr/bin/gcc -v >&5 Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-18+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) configure:2815: $? = 0 configure:2804: /usr/bin/gcc -V >&5 gcc: error: unrecognized command line option '-V' gcc: fatal error: no input files compilation terminated. configure:2815: $? = 1 configure:2804: /usr/bin/gcc -qversion >&5 gcc: error: unrecognized command line option '-qversion'; did you mean '--version'? gcc: fatal error: no input files compilation terminated. configure:2815: $? = 1 configure:2835: checking whether the C compiler works configure:2857: /usr/bin/gcc -g -L/builds/leander.schulten/Lichtsteuerung/vcpkg_installed/x64-linux-windows-static/debug/lib conftest.c -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 >&5 /usr/bin/ld: cannot find -lkernel32 /usr/bin/ld: cannot find -luser32 /usr/bin/ld: cannot find -lgdi32 /usr/bin/ld: cannot find -lwinspool /usr/bin/ld: cannot find -lshell32 /usr/bin/ld: cannot find -lole32 /usr/bin/ld: cannot find -loleaut32 /usr/bin/ld: cannot find -luuid /usr/bin/ld: cannot find -lcomdlg32 /usr/bin/ld: cannot find -ladvapi32 collect2: error: ld returned 1 exit status configure:2861: $? = 1 configure:2899: result: no configure: failed program was: | /* confdefs.h */ | #define PACKAGE_NAME "package-unused" | #define PACKAGE_TARNAME "libbacktrace" | #define PACKAGE_VERSION "version-unused" | #define PACKAGE_STRING "package-unused version-unused" | #define PACKAGE_BUGREPORT "" | #define PACKAGE_URL "" | /* end confdefs.h. */ | | int | main () | { | | ; | return 0; | } configure:2904: error: in `/builds/leander.schulten/Lichtsteuerung/vcpkg/buildtrees/libbacktrace/x64-linux-windows-static-dbg': configure:2906: error: C compiler cannot create executables See `config.log' for more details ## ---------------- ## ## Cache variables. ## ## ---------------- ## ac_cv_build=x86_64-pc-linux-gnu ac_cv_env_CC_set=set ac_cv_env_CC_value=/usr/bin/gcc ac_cv_env_CFLAGS_set=set ac_cv_env_CFLAGS_value=-g ac_cv_env_CPPFLAGS_set= ac_cv_env_CPPFLAGS_value= ac_cv_env_CPP_set=set ac_cv_env_CPP_value=/usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-cpp ac_cv_env_DSYMUTIL_set= ac_cv_env_DSYMUTIL_value= ac_cv_env_LDFLAGS_set=set ac_cv_env_LDFLAGS_value='-L/builds/leander.schulten/Lichtsteuerung/vcpkg_installed/x64-linux-windows-static/debug/lib ' ac_cv_env_LIBS_set=set ac_cv_env_LIBS_value='-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32' ac_cv_env_NM_set= ac_cv_env_NM_value= ac_cv_env_OBJCOPY_set= ac_cv_env_OBJCOPY_value= ac_cv_env_build_alias_set= ac_cv_env_build_alias_value= ac_cv_env_host_alias_set=set ac_cv_env_host_alias_value=mingw32 ac_cv_env_target_alias_set= ac_cv_env_target_alias_value= ac_cv_host=i686-pc-mingw32 ac_cv_prog_CC=/usr/bin/gcc ac_cv_target=i686-pc-mingw32 ## ----------------- ## ## Output variables. ## ## ----------------- ## ACLOCAL='' ALLOC_FILE='' AMTAR='' AM_BACKSLASH='' AM_DEFAULT_V='' AM_DEFAULT_VERBOSITY='' AM_V='' AR='/usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-ar' AUTOCONF='' AUTOHEADER='' AUTOMAKE='' AWK='' BACKTRACE_FILE='' BACKTRACE_SUPPORTED='' BACKTRACE_SUPPORTS_DATA='' BACKTRACE_SUPPORTS_THREADS='' BACKTRACE_USES_MALLOC='' CC='/usr/bin/gcc' CFLAGS='-g' CLOCK_GETTIME_LINK='' COMM='' CPP='/usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-cpp' CPPFLAGS='' CYGPATH_W='' DEFS='' DSYMUTIL='' DUMPBIN='' DWZ='' ECHO_C='' ECHO_N='-n' ECHO_T='' EGREP='' EXEEXT='' EXTRA_FLAGS='' FGREP='' FORMAT_FILE='' GREP='' HAVE_COMM_FALSE='' HAVE_COMM_TRUE='' HAVE_COMPRESSED_DEBUG_FALSE='' HAVE_COMPRESSED_DEBUG_TRUE='' HAVE_DWARF5_FALSE='' HAVE_DWARF5_TRUE='' HAVE_DWZ_FALSE='' HAVE_DWZ_TRUE='' HAVE_ELF_FALSE='' HAVE_ELF_TRUE='' HAVE_LIBLZMA_FALSE='' HAVE_LIBLZMA_TRUE='' HAVE_MINIDEBUG_FALSE='' HAVE_MINIDEBUG_TRUE='' HAVE_OBJCOPY_DEBUGLINK_FALSE='' HAVE_OBJCOPY_DEBUGLINK_TRUE='' HAVE_PTHREAD_FALSE='' HAVE_PTHREAD_TRUE='' HAVE_XZ_FALSE='' HAVE_XZ_TRUE='' HAVE_ZLIB_FALSE='' HAVE_ZLIB_TRUE='' INSTALL_DATA='' INSTALL_PROGRAM='' INSTALL_SCRIPT='' INSTALL_STRIP_PROGRAM='' LD='/usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-ld' LDFLAGS='-L/builds/leander.schulten/Lichtsteuerung/vcpkg_installed/x64-linux-windows-static/debug/lib ' LIBOBJS='' LIBS='-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32' LIBTOOL='' LIPO='' LN_S='' LTLIBOBJS='' MAINT='' MAINTAINER_MODE_FALSE='' MAINTAINER_MODE_TRUE='' MAKEINFO='' MKDIR_P='' NATIVE_FALSE='' NATIVE_TRUE='' NM='' NMEDIT='' OBJCOPY='' OBJDUMP='' OBJEXT='' OTOOL64='' OTOOL='' PACKAGE='' PACKAGE_BUGREPORT='' PACKAGE_NAME='package-unused' PACKAGE_STRING='package-unused version-unused' PACKAGE_TARNAME='libbacktrace' PACKAGE_URL='' PACKAGE_VERSION='version-unused' PATH_SEPARATOR=':' PIC_FLAG='' PTHREAD_CFLAGS='' RANLIB='' READELF='' SED='' SET_MAKE='' SHELL='/bin/sh' STRIP='' USE_DSYMUTIL_FALSE='' USE_DSYMUTIL_TRUE='' VERSION='' VIEW_FILE='' WARN_FLAGS='' XZ='' ac_ct_CC='' ac_ct_DUMPBIN='' am__EXEEXT_FALSE='' am__EXEEXT_TRUE='' am__isrc='' am__leading_dot='' am__tar='' am__untar='' bindir='${prefix}/../tools/libbacktrace/debug/bin' build='x86_64-pc-linux-gnu' build_alias='' build_cpu='x86_64' build_os='linux-gnu' build_vendor='pc' datadir='${datarootdir}' datarootdir='${prefix}/share/libbacktrace' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' dvidir='${docdir}' exec_prefix='NONE' host='i686-pc-mingw32' host_alias='mingw32' host_cpu='i686' host_os='mingw32' host_vendor='pc' htmldir='${docdir}' includedir='${prefix}/../include' infodir='${datarootdir}/info' install_sh='' libdir='${exec_prefix}/lib' libexecdir='${exec_prefix}/libexec' libtool_VERSION='' localedir='${datarootdir}/locale' localstatedir='${prefix}/var' mandir='${datarootdir}/man' mkdir_p='' multi_basedir='' oldincludedir='/usr/include' pdfdir='${docdir}' prefix='/builds/leander.schulten/Lichtsteuerung/vcpkg_installed/x64-linux-windows-static/debug' program_transform_name='s,x,x,' psdir='${docdir}' sbindir='${prefix}/../tools/libbacktrace/debug/sbin' sharedstatedir='${prefix}/com' sysconfdir='${prefix}/etc' target='i686-pc-mingw32' target_alias='mingw32' target_cpu='i686' target_os='mingw32' target_vendor='pc' ## ----------- ## ## confdefs.h. ## ## ----------- ## /* confdefs.h */ #define PACKAGE_NAME "package-unused" #define PACKAGE_TARNAME "libbacktrace" #define PACKAGE_VERSION "version-unused" #define PACKAGE_STRING "package-unused version-unused" #define PACKAGE_BUGREPORT "" #define PACKAGE_URL "" configure: exit 77 and The only thing that worked is adding set(VCPKG_MAKE_BUILD_TRIPLET --host=mingw32)
set(ENV{CC} /usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-gcc)
set(ENV{CXX} /usr/src/mxe/usr/bin/x86_64-w64-mingw32.shared.posix-g++) to And when I add
to |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
the toolchain settings are not available in the |
Beta Was this translation helpful? Give feedback.
-
Does the title need an edit?
|
Beta Was this translation helpful? Give feedback.
-
Does vcpkg detect these compilers at all? AFAIU, it looks for a very restricted set of names: vcpkg/scripts/toolchains/mingw.cmake Lines 24 to 25 in a267ab1 So does it work when you symlink |
Beta Was this translation helpful? Give feedback.
-
Since #17073 was merged, I think this duscission can be closed. |
Beta Was this translation helpful? Give feedback.
Since #17073 was merged, I think this duscission can be closed.