简体   繁体   中英

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

I'm currently working from my home Windows PC on the code, that I compile on a Linux PC over an SSH connection. But since the resulting program creates a GUI, I can't really test it. Is it possible to create, besides the Linux program, a Windows exe that I can run on my home computer? Here is my CMakeLists (using 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})

You could use Linux-hosted MinGW for this, but you will have to build Qt by yourself. It is a complicated process and not all Linux applications run perfectly well on Windows.

Maybe, you can use SSH X11 forwarding with Windows-hosted SSH client with X11 support instead ( MobaXterm , for example) to get application window from the server?

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