{"id":98,"date":"2026-07-19T16:16:14","date_gmt":"2026-07-19T16:16:14","guid":{"rendered":"https:\/\/demensdeum.com\/blog\/2026\/07\/19\/crosscompile-for-window-on-ubuntu-mingw-cmake\/"},"modified":"2026-07-19T16:16:14","modified_gmt":"2026-07-19T16:16:14","slug":"crosscompile-for-window-on-ubuntu-mingw-cmake","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/es\/2026\/07\/19\/crosscompile-for-window-on-ubuntu-mingw-cmake\/","title":{"rendered":"Build for Windows under Ubuntu MinGW CMake"},"content":{"rendered":"<p>In this post I will describe the process of building libraries and applications for Windows using the MinGW32 toolchain on Ubuntu.<br \/>\nInstall wine, mingw:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-unknown\" data-lang=\"unknown\"><code>sudo apt-get install wine mingw-w64\n<\/code><\/pre>\n<\/div>\n<p>After this, you can already build C\/C++ applications for Windows:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-unknown\" data-lang=\"unknown\"><code># C\ni686-w64-mingw32-gcc helloWorld.c -o helloWorld32.exe      # 32-bit\nx86_64-w64-mingw32-gcc helloWorld.c -o helloWorld64.exe    # 64-bit\n \n# C++\ni686-w64-mingw32-g++ helloWorld.cc -o helloWorld32.exe     # 32-bit\nx86_64-w64-mingw32-g++ helloWorld.cc -o helloWorld64.exe   # 64-bit\n<\/code><\/pre>\n<\/div>\n<p>The collected exe can be checked using wine.<br \/>\nNext, let&#8217;s look at the changes to the CMake build, the CMakeLists.txt file, adding MinGW specific things to the build file:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-unknown\" data-lang=\"unknown\"><code>if (MINGW32)\nset(CMAKE_SYSTEM_NAME Windows)\nSET(CMAKE_C_COMPILER i686-w64-mingw32-gcc)\nSET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)\nSET(CMAKE_RC_COMPILER i686-w64-mingw32-windres)\nset(CMAKE_RANLIB i686-w64-mingw32-ranlib)\nendif()\n\n\/\/ \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 shared dll\nelseif (MINGW32)\nadd_library(FlameSteelEngineGameToolkit.dll SHARED ${SOURCE_FILES})\nelse()\n\n\/\/ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438\u043d\u043a\u0443\u0435\u043c \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438\nif (MINGW32)\ntarget_link_libraries(\n                        FlameSteelEngineGameToolkit.dll \n                        -static-libgcc\n                        -static-libstdc++\n                        SDL2 \n                        SDL2_mixer \n                        \/home\/demensdeum\/Sources\/cube-art-project-bootstrap\/FlameSteelFramework\/FlameSteelCore\/FlameSteelCore.dll\n                        \/home\/demensdeum\/Sources\/cube-art-project-bootstrap\/FlameSteelFramework\/FlameSteelBattleHorn\/FlameSteelBattleHorn.dll\n                        \/home\/demensdeum\/Sources\/cube-art-project-bootstrap\/FlameSteelFramework\/FlameSteelCommonTraits\/FlameSteelCommonTraits.dll)\n\nset_target_properties(FlameSteelEngineGameToolkit.dll PROPERTIES\n        PREFIX \"\"\n        SUFFIX \"\"\n        LINK_FLAGS \"-Wl,--add-stdcall-alias\"\n        POSITION_INDEPENDENT_CODE 0 # this is to avoid MinGW warning; \n        # MinGW generates position-independent-code for DLL by default\n)\nelse()\n<\/code><\/pre>\n<\/div>\n<p>We collect:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-unknown\" data-lang=\"unknown\"><code>cmake -DMINGW32=1 .\nmake\n<\/code><\/pre>\n<\/div>\n<p>The output will be a dll or exe, depending on what you are collecting. For a working example, you can look at the repository of the new Cube-Art-Project and its libraries:<br \/>\n<a href=\"https:\/\/gitlab.com\/demensdeum\/cube-art-project\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/gitlab.com\/demensdeum\/cube-art-project<\/a><\/p>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/FlameSteelEngineGameToolkitFSGL\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/gitlab.com\/demensdeum\/FlameSteelEngineGameToolkitFSGL<\/a><\/p>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/cube-art-project-bootstrap\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/gitlab.com\/demensdeum\/cube-art-project-bootstrap<\/a><\/p>\n<p>Sources<br \/>\n<a href=\"https:\/\/arrayfire.com\/cross-compile-to-windows-from-linux\/\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/arrayfire.com\/cross-compile-to-windows-from-linux\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will describe the process of building libraries and applications for Windows using the MinGW32 toolchain on Ubuntu. Install wine, mingw: sudo apt-get install wine mingw-w64 After this, you can already build C\/C++ applications for Windows: # C i686-w64-mingw32-gcc helloWorld.c -o helloWorld32.exe # 32-bit x86_64-w64-mingw32-gcc helloWorld.c -o helloWorld64.exe # 64-bit # C++ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-notes"],"translation":{"provider":"WPGlobus","version":"3.0.3","language":"es","enabled_languages":["en","ru","zh","de","ja","fr","es","pt","hi"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"es":{"title":false,"content":false,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false},"hi":{"title":true,"content":true,"excerpt":false}}},"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":0,"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/es\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}