1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| cmake_minimum_required(VERSION 3.21) project(hello_world)
set(CMAKE_CXX_STANDARD 14)
add_executable(hello_world main.cpp)
# 设置交叉编译的目标操作为windows SET(CMAKE_SYSTEM_NAME Windows) # 指定c/c++编译器 SET(CMAKE_C_COMPILER i686-w64-mingw32-gcc) SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres) # 指定编译目标操作系统版本时的搜索根路径 SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
# adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # 解决找不到libstdc++-6.dll set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
|