{"id":2285,"date":"2019-10-18T09:17:02","date_gmt":"2019-10-18T06:17:02","guid":{"rendered":"http:\/\/demensdeum.com\/blog\/?p=2285"},"modified":"2024-12-16T22:32:33","modified_gmt":"2024-12-16T19:32:33","slug":"crosscompile-for-window-on-ubuntu-mingw-cmake","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/fr\/2019\/10\/18\/crosscompile-for-window-on-ubuntu-mingw-cmake\/","title":{"rendered":"Construire pour Windows sous Ubuntu MinGW CMake"},"content":{"rendered":"<p>Dans cet article, je d\u00e9crirai le processus de cr\u00e9ation de biblioth\u00e8ques et d&#8217;applications pour Windows \u00e0 l&#8217;aide de la cha\u00eene d&#8217;outils MinGW32 sur Ubuntu.<br \/>Installez wine, mingw\u00a0:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>sudo apt-get install wine mingw-w64\n<\/code><\/pre>\n<\/div>\n<p>Apr\u00e8s cela, vous pouvez d\u00e9j\u00e0 cr\u00e9er des applications C\/C++ pour Windows\u00a0:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-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>L&#8217;exe collect\u00e9 peut \u00eatre v\u00e9rifi\u00e9 \u00e0 l&#8217;aide de wine.<\/p>\n<p>Ensuite, regardons les modifications apport\u00e9es \u00e0 la build CMake, le fichier CMakeLists.txt, en ajoutant des \u00e9l\u00e9ments sp\u00e9cifiques \u00e0 MinGW au fichier de build\u00a0:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-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>Collecte\u00a0:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>cmake -DMINGW32=1 .\nmake\n<\/code><\/pre>\n<\/div>\n<p>Le r\u00e9sultat sera une DLL ou un exe, selon ce que vous collectez. Pour un exemple fonctionnel, vous pouvez consulter le r\u00e9f\u00e9rentiel du nouveau Cube-Art-Project et ses biblioth\u00e8ques\u00a0:<br \/><a href=\"https:\/\/gitlab.com\/demensdeum\/cube-art-project\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/gitlab.com\/demensdeum\/cube-art-project<\/a><br \/>\n<a href=\"https:\/\/gitlab.com\/demensdeum\/FlameSteelEngineGameToolkitFSGL\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/gitlab.com\/demensdeum\/FlameSteelEngineGameToolkitFSGL<\/a><br \/>\n<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 \/><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>Dans cet article, je d\u00e9crirai le processus de cr\u00e9ation de biblioth\u00e8ques et d&#8217;applications pour Windows \u00e0 l&#8217;aide de la cha\u00eene d&#8217;outils MinGW32 sur Ubuntu.Installez wine, mingw\u00a0: sudo apt-get install wine mingw-w64 Apr\u00e8s cela, vous pouvez d\u00e9j\u00e0 cr\u00e9er des applications C\/C++ pour Windows\u00a0: # C i686-w64-mingw32-gcc helloWorld.c -o helloWorld32.exe # 32-bit x86_64-w64-mingw32-gcc helloWorld.c -o helloWorld64.exe #<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/fr\/2019\/10\/18\/crosscompile-for-window-on-ubuntu-mingw-cmake\/\">Continue reading <span class=\"screen-reader-text\">&#8220;Construire pour Windows sous Ubuntu MinGW CMake&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,52],"tags":[],"class_list":["post-2285","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"fr","enabled_languages":["en","ru","zh","de","fr","ja","pt"],"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},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/posts\/2285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/comments?post=2285"}],"version-history":[{"count":13,"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/posts\/2285\/revisions"}],"predecessor-version":[{"id":3937,"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/posts\/2285\/revisions\/3937"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/media?parent=2285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/categories?post=2285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/fr\/wp-json\/wp\/v2\/tags?post=2285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}