{"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\/zh\/2019\/10\/18\/crosscompile-for-window-on-ubuntu-mingw-cmake\/","title":{"rendered":"\u5728 Ubuntu MinGW CMake \u4e0b\u6784\u5efa Windows"},"content":{"rendered":"<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u63cf\u8ff0\u5728 Ubuntu \u4e0a\u4f7f\u7528 MinGW32 \u5de5\u5177\u94fe\u4e3a Windows \u6784\u5efa\u5e93\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u3002<br \/>\u5b89\u88c5wine\u3001mingw\uff1a<\/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>\u6b64\u540e\uff0c\u60a8\u5c31\u53ef\u4ee5\u4e3a Windows \u6784\u5efa C\/C++ \u5e94\u7528\u7a0b\u5e8f\u4e86\uff1a<\/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>\u53ef\u4ee5\u4f7f\u7528wine\u68c0\u67e5\u6536\u96c6\u7684exe\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u5bf9 CMake \u6784\u5efa\u3001CMakeLists.txt \u6587\u4ef6\u7684\u66f4\u6539\uff0c\u5c06 MinGW \u7279\u5b9a\u7684\u5185\u5bb9\u6dfb\u52a0\u5230\u6784\u5efa\u6587\u4ef6\u4e2d\uff1a<\/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>\u6536\u96c6\uff1a<\/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>\u8f93\u51fa\u5c06\u662f dll \u6216 exe\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u60a8\u8981\u6536\u96c6\u7684\u5185\u5bb9\u3002\u5bf9\u4e8e\u4e00\u4e2a\u5de5\u4f5c\u793a\u4f8b\uff0c\u60a8\u53ef\u4ee5\u67e5\u770b\u65b0\u7684 Cube-Art-Project \u53ca\u5176\u5e93\u7684\u5b58\u50a8\u5e93\uff1a<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>\u6765\u6e90<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>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u63cf\u8ff0\u5728 Ubuntu \u4e0a\u4f7f\u7528 MinGW32 \u5de5\u5177\u94fe\u4e3a Windows \u6784\u5efa\u5e93\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u3002\u5b89\u88c5wine\u3001mingw\uff1a sudo apt-get install wine mingw-w64 \u6b64\u540e\uff0c\u60a8\u5c31\u53ef\u4ee5\u4e3a Windows \u6784\u5efa C\/C++ \u5e94\u7528\u7a0b\u5e8f\u4e86\uff1a # 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++ i686-w64-mingw32-g++ helloWorld.cc -o helloWorld32.exe # 32-bit x86_64-w64-mingw32-g++ helloWorld.cc -o helloWorld64.exe # 64-bit \u53ef\u4ee5\u4f7f\u7528wine\u68c0\u67e5\u6536\u96c6\u7684exe\u3002 \u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u5bf9 CMake \u6784\u5efa\u3001CMakeLists.txt \u6587\u4ef6\u7684\u66f4\u6539\uff0c\u5c06 MinGW \u7279\u5b9a\u7684\u5185\u5bb9\u6dfb\u52a0\u5230\u6784\u5efa\u6587\u4ef6\u4e2d\uff1a if (MINGW32) set(CMAKE_SYSTEM_NAME<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/zh\/2019\/10\/18\/crosscompile-for-window-on-ubuntu-mingw-cmake\/\">Continue reading <span class=\"screen-reader-text\">&#8220;\u5728 Ubuntu MinGW CMake \u4e0b\u6784\u5efa Windows&#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":"zh","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\/zh\/wp-json\/wp\/v2\/posts\/2285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/comments?post=2285"}],"version-history":[{"count":13,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/posts\/2285\/revisions"}],"predecessor-version":[{"id":3937,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/posts\/2285\/revisions\/3937"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/media?parent=2285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/categories?post=2285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/tags?post=2285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}