Howdy, Ubuntu on Windows! Writing for Compiled Languages

951

Microsoft’s addition of the Bash shell and Ubuntu user space in Windows 10 is a real win for developers everywhere. Dozens of compilers and thousands of libraries are now immediately available on Windows desktops.  In this article, we’re going to write the classic “hello world” application in several different compiled languages, install any necessary dependencies, and execute our compiled code.

If you’d like to follow along this article and try out these examples, you can grab all of the source code from git:

$ sudo apt update

$ sudo apt install -y git

$ git clone https://github.com/dustinkirkland/howdy-windows.git

$ cd howdy-windows

$ make

Now, let’s look at each language:

  1. C

  • Installation

$ sudo apt install -y gcc

  • Code: c/howdy.c

#include <stdio.h>

int main() {

       printf(”    ====> C: Howdy, Windows!n”);

       return 0;

}

  • Compilation

$ gcc -o c/howdy c/howdy.c

  • Execution

        $ ./c/howdy

   ====> C: Howdy, Windows!

  1. C++

  • Installation

$ sudo apt install -y g++

  • Code: cpp/howdy.cpp

        #include <iostream>

int main() {

       std::cout << ”    ====> C++: Howdy, Windows!n”;

}

  • Compilation

$ g++ -o cpp/howdy cpp/howdy.cpp

  • Execution

        $ ./cpp/howdy

   ====> C++: Howdy, Windows!

  1. Golang

  • Installation

$ sudo apt install -y golang

  • Code: golang/howdy.go

        package main

import “fmt”

func main() {

       fmt.Printf(”    ====> Golang: Howdy, Windows!n”)

}

  • Compilation

$ go build -o golang/howdy golang/howdy.go

  • Execution

        $ ./golang/howdy

   ====> Golang: Howdy, Windows!

  1. Fortran

  • Installation

$ sudo apt install -y gfortran

  • Code: fortran/howdy.f90

            program howdy

 print *, ”    ====> Fortran: Howdy, Windows!”

end program howdy

  • Compilation

$ gfortran fortran/howdy.f90 -o fortran/howdy

  • Execution

        $ ./fortran/howdy

    ====> Fortran: Howdy, Windows!

  1. Pascal

  • Installation

$ sudo apt install -y fp-compiler

  • Code: pascal/howdy.pas

        program Howdy;

Begin

       writeln(‘    ====> Pascal: Howdy, Windows!’);

end.

  • Compilation

$ pc pascal/howdy.pas

  • Execution

        $ ./pascal/howdy

   ====> Pascal: Howdy, Windows!

  1. Erlang

  • Installation

$ sudo apt install -y erlang-base

  • Code: erlang/howdy.erl

        -module(howdy).

-export([howdy/0]).

howdy() -> io:fwrite(”    ====> Erlang: Howdy, Windows!n”).

  • Compilation

$ erlc erlang/howdy.erl

  • Execution

        $ erl -noshell -s howdy howdy -s init stop

   ====> Erlang: Howdy, Windows!

 

Cheers,

Dustin

 

Read the next article: Howdy, Ubuntu on Windows! How Fast Is It?

Read previous articles in the series:

Howdy, Ubuntu on Windows! An Intro From Canonical’s Dustin Kirkland

Howdy, Ubuntu on Windows! Getting Started

Howdy, Ubuntu on Windows! Ubuntu Commands Every Windows User Should Learn

Howdy, Ubuntu on Windows! Write and Execute Your First Program

Learn more about Running Linux Workloads on Microsoft Azure in this on-demand webinar with guest speaker Ian Philpot of Microsoft. Watch Now >>