ぷろみん

プログラミング的な内容を扱ってます

debianでglfwをコンパイルしてwindows向けバイナリを作成する

概要

windows環境での話です。
最近msys-gitやmysy2を使ったりで環境変数やら実行バイナリがごちゃごちゃしてきてしまったので、実験用の環境が欲しくなったので仮想化してみます。

事前準備

管理者権限が必要なパッケージもあります。

  • chocolatly
    https://chocolatey.org/
    サイトに記載されているコマンドを打てばインストールできます。

  • virtual box

$choco install virtualbox
$choco install vagrant
$choco install virtualbox.extensionpack

もしかしたらOpenSSHも必要かもしれません。

choco install openssh

sshはパスが自動で付かないかもしれません。

Windows 8.1ではじめるイマドキの開発環境 - Qiita

vagrant

http://www.vagrantbox.es/から好きなboxを引っ張ってきます。 とりあえずDebianでいきます。

#powershell か msys-mingw
$mkdir debian
$cd debian
$vagrant box add https://atlas.hashicorp.com/ARTACK/boxes/debian-jessie
$vagrant box list
ARTACK/debian-jessie (virtualbox, 8.1.0)
$vagrant init ARTACK/debian-jessie
$vagrant up
$vagrant ssh

Oracle VM VirtualBox Extension Packを入れていないとvagrant upの際に以下のエラーがでます。

The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'poweroff' state. Please verify everything is configured
properly and try again.

If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open.

The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.

言われた通りGUIで起動してみます。
するとImplementation of the USB 2.0 controller not found!というエラーが出ます。

ビルド

ここからはvagrantで起動したdebian上での実行例です。

# 必要なパッケージを揃える
$sudo aptitude update
$sudo aptitude -V -D -y install git
$sudo aptitude -V -D -y install cmake
$sudo aptitude -V -D -y install mingw-w64

# mingw版のglfwをビルド
$git clone https://github.com/glfw/glfw
$cd glfw
$cmake -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake .
$make
$sudo make install

# http://www.glfw.org/docs/latest/quick.htmlにあるサンプルをhello.cppとして保存

$x86_64-w64-mingw32-g++ -I/usr/local/include hello.cpp -L/usr/local/lib -lglfw3 -lopengl32 -lwinmm -lgdi32
# windowsとの共有フォルダに実行ファイルを送る
$mv a.exe /vagrant/a.exe

windows側からa.exeを実行すると無事に実行できました。

後片付け

遊び終わったら環境を片付けましょう。

# debian
$exit

# windows
$vagrant halt
$vagrant destroy --force