Help us understand the problem. What is going on with this article?

HaskellでGUIやるためのgi-gtkのHelloWorld!まで(macOS,Stack)

はじめに

Haskellには他にもGUIを扱うためのライブラリが存在しますが、ここではgi-gtkのみ扱います。

筆者の環境

macOS Mojave 10.14.6
stack 2.1.3

導入の前に

僕は死ぬほどエラーが出たのでFreeType2の最新版をダウンロードしておくと良いでしょう
参考にしたページ

導入手順

stack new hoge

で適当にhogeプロジェクトを作成します。

package.yamlに

dependencies:
- base >= 4.7 && < 5
- gi-gtk
- haskell-gi-base

と付け加え、プロジェクト側の操作は終了。ターミナルで以下のように入力し、

brew install gobject-introspection gtk+ gtk+3
export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig

いざビルド。

gitにあるのと全く一緒ですが一応サンプルコード

{-# LANGUAGE OverloadedLabels  #-}
{-# LANGUAGE OverloadedStrings #-}

import           Data.GI.Base
import qualified GI.Gtk       as Gtk

main :: IO ()
main = do
  Gtk.init Nothing

  win <- new Gtk.Window [ #title := "Hello World!" ]

  on win #destroy Gtk.mainQuit

  #showAll win

  Gtk.main

d5fcfe37a0c801e1e48c9a1053e3c38e.png

こんな感じですね、お疲れ様でした。

参考記事

https://qiita.com/mimaburao/items/47135e641106e9ba7aa8

https://github.com/haskell-gi/haskell-gi
実は内容はほとんど同じなのですが、freetype2を入れるのと環境変数をぶち込むところで若干詰まったので共有しておきます。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away