Saturday, 16 April 2016

Graphical C++ program in the Codenvy cloud

Graphical FLTK based C++ program in the Codenvy cloud with CMAKE

Let's draw some Acid-Smileys on an FLTK window from a C++ program compiled with gcc using the CMake build tool.

You might want to read my earlier Blog about running a C++ Hello World with Codenvy if you are not familiar with Codenvy.

Step 1: Create the project by cloning this Git repo:

The code is based on sample code and a learning exercise from Bjarne Stroustrup's Programming -- Principles and Practice Using C++

Step 2: Create your own Runner

Expand the Runner panel by clicking on the button "Runners" at the bottom edge of the IDE window.
Click on the tab Configs. 
Then click on "+ Create New"
In the middle, change the Name to "X-Runner"
Slide the Project default slide to On
Mark all the text in the Dockerfile and remove it. Replace it with the lines below.
Click Save 

FROM codenvy/cpp_qt4
RUN sudo apt-get update
RUN sudo apt-get -y install \
   libfltk1.3-dev \
   libpng++-dev \
   libjpeg-dev \
   libxinerama-dev \
   libXft-dev \
   libfontconfig-dev \
   cmake vim
ADD $app$ /home/user/
RUN mkdir build && cd build && cmake .. && make

The FROM line is the baseline codenvy environment

The next two RUN commands request the Debian Jessie container to refresh it's repo and to install a number of development packages. Most important is libfltk1.3-dev as the program is written against this GUI framework. The other libraries are required to link the final code. They need to be installed explicitly as the libfltk package doesn't declare these as dependencies.

The ADD line copies the files from the IDE into the container

The final RUN makes a build dir, switches into it and runs cmake. Cmake looks for the FLTK library and creates a complicated Makefile. After this step all we have to do is call make to compile the program.

Step 3 execute the Runner

In the top right pick the X-Runner in the drop down menu.
Then click on the little green play icon.

Step 4 Open the VNC window

Look for the hyperlink underneath the Console panel. When it appears click on it to open the X-Window tab.

Step 5 Open a Terminal

Right click on the grey area. In the pop-up that appears click on Terminal.

Step 6 run the program

In the terminal window type: build/ClassedAcidSmiley and press Enter

(To close the GUI hit Ctrl-C on the terminal.)
(To end the runner click on the red icon in the IDE window.)

No comments:

Post a Comment