この投稿では、Ubuntu で MinGW32 ツールチェーンを使用して Windows 用のライブラリとアプリケーションを構築するプロセスについて説明します。
wine をインストールします。
sudo apt-get install wine mingw-w64
これで、Windows 用の 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
収集したexeはwineを使用して確認できます。
次に、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
出力は、収集している内容に応じて dll または exe になります。実際の例として、新しい Cube-Art-Project とそのライブラリのリポジトリをご覧ください。
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/