是否可以使用带有 CMake 的 C++ 在 Linux 上创建 Windows exe?

Is it possible to create a Windows exe on Linux using C++ with CMake?

我目前正在家里 Windows PC 上编写代码,我通过 SSH 连接在 Linux PC 上编译。但是由于生成的程序创建了一个 GUI,我无法真正测试它。除了 Linux 程序之外,是否可以创建一个 Windows exe,我可以在我的家用计算机上 运行? 这是我的 CMakeLists(使用 QT5):

cmake_minimum_required(VERSION 2.8.11)
project(p3)

set(CMAKE_PREFIX_PATH $ENV{QT5_QMAKE_DIR})
MESSAGE(STATUS "QT5_QMAKE_DIR: " ${CMAKE_PREFIX_PATH})

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_AUTOMOC ON)

# Possibly set this to DEBUG for testing
set(CMAKE_BUILD_TYPE Release)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
#project source directories

find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)

find_package(OpenMP)
if (OPENMP_FOUND)
   message("OPENMP FOUND")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

include_directories(
  ${Qt5Widgets_INCLUDE_DIRS}
  ${Qt5Core_INCLUDE_DIRS}
  ${Qt5Gui_INCLUDE_DIRS}
)

add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")

if(UNIX)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

add_executable(p3
   #.cpps and .hs
)

set_property(TARGET p3 PROPERTY CXX_STANDARD 11)
target_link_libraries(p3 ${Qt5Widgets_LIBRARIES})

您可以为此使用 Linux-hosted MinGW,但您必须自己构建 Qt。这是一个复杂的过程,并非所有 Linux 应用程序 运行 在 Windows.

上都完美无缺

也许,您可以使用 SSH X11 forwarding with Windows-hosted SSH client with X11 support instead (MobaXterm,例如)从服务器获取应用程序 window?