Writing a GTK progam in D, using Ubuntu in windows
There are a couple of stages to this. Firstly - getting windowed programs running from a linux in windows subprogram, then installing the development libraries, finally compiling the program itself. If you are intending to use the language for more than a bit of poking around, I would strongly suggest that you install dub and set everything up using the package management tooling. It will make things much easier.
Setting up X11 for linux-in-windows
There's an easy way to check if you need to do this: see if a gui window will pop up for an existing application. Using gedit as an example (if you don't have this "sudo apt-get install gedit")
$ gedit
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused
(gedit:9443): Gtk-WARNING **: cannot open display:
If the display can't be opened, then you need to open an x-windows interface in windows. Xming will do the trick. On first use, the windows firewall will probably pop up a messaging saying that it's blocking external connections. For internal use, you don't need to release the firewall constraint.
You need to set bash shell so that it will send the display to the xserver. By default the xserver will run on "0:0" (the xming tooltip will say what channel it is using). Execute "export DISPLAY=:0" so the bash shell uses that display.
Installing the development libraries.
This uses the GTK3 D libraries (gtkd3). This is the simplest way to get the libraries into place. Alternatively, there's the installation from original source code as described here; note there are issues with the 2.3.0 GtkD source code used on that page that makes the installation not compile. That version of the library is also out of date.
Follow the instructions on https://d-apt.sourceforge.io/.
$ sudo wget https://netcologne.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list
$ sudo apt-get update --allow-insecure-repositories && sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring && sudo apt-get update
$ sudo apt-get install libgtkd3-dev libgtkd3-doc
This will force the installation of the gtk3 development libraries, and all their requirements.
Executing code
Using example code from https://sites.google.com/site/gtkdtutorial/.
gtk_test.d
import gtk.MainWindow;
import gtk.Label;
import gtk.Main;
void main(string[] args)
{
Main.init(args);
MainWindow win = new MainWindow("Hello World");
win.setDefaultSize(200, 100);
win.add(new Label("Hello World"));
win.showAll();
Main.run();
}
dmd `pkg-config --cflags --libs gtkd-3` gtk_test.d
(sudo apt-get install dmd-compiler will install the dmd compiler).
./gtk_test.o should then execute the executable.