QBLOG

alt

Yvan Janssens

My personal ramblings from stomping out random bugs

IBM i "Hello World" in ILE C

Yvan Janssens
May 28 2019 01:01:35 PM
This tutorial will guide you through writing a simple Hello World application in ILE C and running it.
Difficulty Easy
Requirements Basic C knowledge
TN5250 Client
IBM i V5R4 or Higher
Compilers and dev tools installed on the i box.








Table of contents


1. Create Source Physical File

2. Write/enter code

3. Compile the code

4. Run the code


1. Create Source Physical Files


Source code files on IBM i are stored in special kinds of Physical Files. These files have source members, which would effectively be your individual source files. IBM i does not offer subdirectories in these so this is a flat directory structure.


To create a source physical file, you  use the
CRTSRCPF command. Use F4 after entering the command to open the prompt screen:

Image:IBM i "Hello World" in ILE C
For this tutorial, we are creating the source physical file "HELLOC" in the library "YVANJ" (which is the default library for my user profile).

2. Write / enter code

For the purpose of this tutorial we are going to use the built-in IDE "Program Development Manager". You can start this IDE using the 'STRPDM' command:


Image:IBM i "Hello World" in ILE C

We continue by selecting "3. Work with members" and respond with the data of the source physical file we just created:


Image:IBM i "Hello World" in ILE C

You will be greeted with the contents of your source physical file, which should be empty:


Image:IBM i "Hello World" in ILE C

Hit F6 on your keyboard (Create), and fill out the form as below:


Image:IBM i "Hello World" in ILE C


Hit Enter to confirm.

You will be greeted with SEU, the Source Entry Utility. Enter the following code snipped and make sure to not press enter, just change your cursor position with the arrow keys:


Image:IBM i "Hello World" in ILE C

After filling out the snippet, hit enter, and then F3.

Image:IBM i "Hello World" in ILE C

Keep these defaults, and press enter again. You have now created your first C code file on IBM i:


Image:IBM i "Hello World" in ILE C


3. Compiling the code

C code on IBM i is compiled using the
CRTBNDC command. Back out of the screen you are currently at by repeatedly hitting F3 until you're back on the main menu. Issue CRTBNDC and finish with F4 to open the auto-complete form as before:

Image:IBM i "Hello World" in ILE C

Program is the output binary, and the indented library below it is the library you want to store your executable. In my case, this is a binary with the name 'hello' in the 'yvanj' library. The next three parameters denote the source physical file and the source member to compile; we use the HelloC source (physical) file we created earlier and specify the library in which we created it. Then we specify the source member we created using the F6 command earlier. We finish with Enter.

After a short while, the following status line should become visible:


Image:IBM i "Hello World" in ILE C


4. Run the code

Running our application is fairly simple, you can call a program by issuing CALL LIBRARY/PROGRAM. In our case this would become CALL YVANJ/HELLO

This will result in the following output:

Image:IBM i "Hello World" in ILE C