Ubuntu MinGW CMake के अंतर्गत विंडोज़ के लिए निर्माण करें

Written by

in

इस पोस्ट में मैं उबंटू पर MinGW32 टूलचेन का उपयोग करके विंडोज़ के लिए लाइब्रेरी और एप्लिकेशन बनाने की प्रक्रिया का वर्णन करूंगा।
वाइन स्थापित करें, मिंगव:

sudo apt-get install wine mingw-w64

इसके बाद, आप पहले से ही विंडोज़ के लिए C/C++ एप्लिकेशन बना सकते हैं:

# 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

एकत्रित एक्सई को वाइन का उपयोग करके जांचा जा सकता है।
इसके बाद, आइए CMake बिल्ड, CMakeLists.txt फ़ाइल में परिवर्तनों को देखें, बिल्ड फ़ाइल में MinGW विशिष्ट चीज़ें जोड़ते हुए:

if (MINGW32)
set(CMAKE_SYSTEM_NAME Windows)
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_RANLIB i686-w64-mingw32-ranlib)
endif()

// для сборки shared dll
elseif (MINGW32)
add_library(FlameSteelEngineGameToolkit.dll SHARED ${SOURCE_FILES})
else()

// обязательно линкуем со всеми зависимостями
if (MINGW32)
target_link_libraries(
                        FlameSteelEngineGameToolkit.dll 
                        -static-libgcc
                        -static-libstdc++
                        SDL2 
                        SDL2_mixer 
                        /home/demensdeum/Sources/cube-art-project-bootstrap/FlameSteelFramework/FlameSteelCore/FlameSteelCore.dll
                        /home/demensdeum/Sources/cube-art-project-bootstrap/FlameSteelFramework/FlameSteelBattleHorn/FlameSteelBattleHorn.dll
                        /home/demensdeum/Sources/cube-art-project-bootstrap/FlameSteelFramework/FlameSteelCommonTraits/FlameSteelCommonTraits.dll)

set_target_properties(FlameSteelEngineGameToolkit.dll PROPERTIES
        PREFIX ""
        SUFFIX ""
        LINK_FLAGS "-Wl,--add-stdcall-alias"
        POSITION_INDEPENDENT_CODE 0 # this is to avoid MinGW warning; 
        # MinGW generates position-independent-code for DLL by default
)
else()

हम एकत्र करते हैं:

cmake -DMINGW32=1 .
make

आप जो एकत्र कर रहे हैं उसके आधार पर आउटपुट एक डीएलएल या एक्सई होगा। एक कामकाजी उदाहरण के लिए, आप नए क्यूब-आर्ट-प्रोजेक्ट और उसके पुस्तकालयों के भंडार को देख सकते हैं:
https://gitlab.com/demensdeum/cube-art-project

https://gitlab.com/demensdeum/FlameSteelEngineGameToolkitFSGL

https://gitlab.com/demensdeum/cube-art-project-bootstrap

स्रोत
https://arrayfire.com/cross-compile-to-windows-from-linux/

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

DemensDeum
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.