
\documentclass[11pt]{article}
\setlength{\textwidth}{5.5in}
%\setlength{\evensidemargin}{-0.5in}
\usepackage{TRmydraft} % title page report
\usepackage{wmff} % algorithm
\usepackage{yprob} % algorithm listing, code, report exercises

\usepackage{graphicx}
\usepackage{float}
\usepackage{url}

\pagestyle{myheadings}
\markright{Using CodeBlocks\hfill}

\begin{document}

\reptitle{\bf Developing OOSimL and C++ Programs}
\author{Dr. Jos\'e M. Garrido}

%\date{February, 2015}

\subtitle{{\bf Using Codeblocks}}
\subsubtitle{\bf on Linux}


\authoraffil{Department of Computer Science} 
 
%
%\halftitlepage
%

\titlepage

\mdraft
%\maketitle
%\newpage
%\tableofcontents
%\newpage





\section{Introduction}


There are several Integrated Development Environments (IDEs) that help implementation of  programs written in C, C++, Fortran, and other programming languages.  Eclipse is one of the most complete and powerful tools, it is mainly useful for Java programs and in general, it can be very slow. For C++, C, and Fortran programs, Codeblocks and CodeLite are faster, lighter, and more convenient to use.  

This document briefly explains implementing OOSimL programs using CodeBlocks on Linux and linking with the simulation library {\tt oosimlib}. 
 For a more detailed introduction to CodeBlocks, refer to various websites with CodeBlocks tutorial and documentation. For a simple but complete tutorial, visit the web page:
 
\medskip
 \url{ksuweb.kennesaw.edu/~jgarrido/comp_models}. 
\medskip

\section{Preparing CodeBlocks}

The following sequence of steps involve the basic procedure for setting the appropriate options on Codeblocks for using the OOSimL translator then the remaining steps for editing C++ programs, compiling,  and linking with the simulation library.
 
\subsection{Download the OOSimL Translator}
The preliminary step required is the installation of the the  translator and simulation library in the computer system running Linux. The 32-bit and the 64-bit versions of OOSimL translator are available on the web page mentioned previously. Use a package manager such as  Synaptic, Ubuntu Software Center, or other to install the GSL. 

\begin{enumerate}
\item
Download the archive file {\tt SCL\_soft\_models.tar.gz} from the web page and extract  all files from archive. 
\item
Select the executable file of the SCL translator ({\tt scl.out} or {\tt scl64.out} depending on the version of Linux your computer (32-bit or 64-bit).
Rename {\tt scl64.out} to {\tt scl.out} in a 64-bit Linux. 
This executable file, the {\tt scl} script file and the {\tt scl.h} file  must be stored on a folder such as \url{~/SCL}.
\end{enumerate}

\subsection{Setting the Codeblocks Options}
\begin{enumerate}
\item
Start CodeBlocks, the screen that appears is shown in Figure~\ref{fig:cb_start}. Click on ‘Create a new project'.

\begin{figure}[H]
\centering
\includegraphics[width=3.75in]{figs/CB_start.png}
\caption{Starting Codeblocks.}
\label{fig:cb_start}
\end{figure}

\item
On the top bar click on the Settings menu, then select Compiler. A dialog box appears. On the  tab group, activate the Other Options tab, and click the button Advanced options located on the lower right of the dialog box. See Figure~\ref{fig:cb_gset}. 

\begin{figure}[H]
\centering
\includegraphics[width=4.0in]{figs/CB_Global_set.png}
\caption{Selecting Advanced options.}
\label{fig:cb_gset}
\end{figure}

\item
Click the Yes button when the box {\em Edit advanced compiler setting?} appears.
\item
On the new window that appears, click the '+' button and type {\tt scl} in the dialog box. 
\item
Type the Command line macro and the Generated files. 
The window will now appear as shown in Figure~\ref{fig:cb_adv_scl}. This assumes that the SCL translator  ( executable file {\tt scl}) is locate in folder: 
\url{~/SCL}

\begin{figure}[H]
\centering
\includegraphics[width=4.25in]{figs/CB_Ad_comp_opt_SCL.png}
\caption{Adding the SCL extension and command for translating SCL files.}
\label{fig:cb_adv_scl}
\end{figure}

\item
Click the Ok button located on the bottom of the window.
\end{enumerate}

Codeblocks is now setup to recognize source files with an {\tt scl} extension for editing and invoking the SCL translator.




\subsection{Using Codeblocks for Implementing SCL Programs}

\begin{enumerate}
\item 
Select Console Application and click the Go button, which is located on the upper right corner of the window. 


\item
On the Console Application window, click the Next button.  Select C language and click Next.
\item
Type the project title (name), e.g. {\em Welcome}. In this example, the project will be created in folder: \url{/home/jgarrido/comp_models/scl_models}, as shown in  Figure~\ref{fig:cb_proj}. Click the Next button.

\begin{figure}[H]
\centering
\includegraphics[width=3.75in]{figs/CB_wel_proj.png}
\caption{Title and location of project.}
\label{fig:cb_proj}
\end{figure}

\item
Select GNU GCC Compiler and click the Finish button.
\item
Activate the left pane of the screen ( Management), click the Projects tab. Remove the C source file  ‘main.c’ by right-clicking on it. The file appears on the editor pane. Now you can edit this C source file.  
\item
A new source file can be created by selecting File menu, then New, and Empty file. Click Yes to add this empty to the project.  A new  dialog window appears, type the name of the file with its {\tt scl} extension. Now you can start editing this source file  and when finished, save the file.

\item
If one or more \underline{existing} source files are to be included in the project, select the Project menu  on the top bar, or right-click on the project name. Select Add files. Select the directory of the source to add to the project and select the SCL source file(s). Click Open, see Figure~\ref{fig:cb_files}.

\begin{figure}[H]
\centering
\includegraphics[width=3.75in]{figs/CB_Ad_comp_opt_SCL.png}
\caption{Adding an existing SCL source file to a project.}
\label{fig:cb_files}
\end{figure}


\item
The source files are now under ‘Others’ and under the project name. Double-click on the desired source file to edit it further. The file now appears on the edit area of the screen, as shown in Figure~\ref{fig:cb_editing}.

\begin{figure}[H]
\centering
\includegraphics[width=4.25in]{figs/wel_edit.png}
\caption{Editing an SCL program.}
\label{fig:cb_editing}
\end{figure}

\item
Right-click on the current project name, or activate the Project menu in the top bar, and select ‘Build options’. 
\begin{enumerate}
\item
 On the tab ‘Compiler settings’, check ‘Enable all compiler warnings’. 
\item
This is an optional step, for small programs may not be required. For computational models, at least the GSL library may need to be added. On the tab ‘Linker settings’, click the ‘Add’ button to add a library to the project. Repeat to add all necessary object files and libraries. For example, for a model {\tt Plineq\_sol3}, a local library {\tt basic\_lib}, two GSL sub-libraries are added {\tt gsl} and {\tt gslcblas}, and the {\tt m}   (standard math library). This is shown in Figure~\ref{fig:cb_link}.  

\begin{figure}[H]
\centering
\includegraphics[width=4.25in]{figs/CB_Projbuild_opt_GSL.png}
\caption{Linker settings.}
\label{fig:cb_link}
\end{figure}

\item
On the tab ‘Search directories’ and the tab 'Compiler',  add the search directory for header files required by the source program while compiling. In Figure~\ref{fig:cb_csearch}, the header file required by the  program is located in the folder \url{~/SCL}.

\begin{figure}[H]
\centering
\includegraphics[width=3.25in]{figs/wel_Add_search_dir.png}
\caption{Adding a compiler search directory.}
\label{fig:cb_csearch}
\end{figure}

\item
On the tab ‘Search directories’ and the tab 'Linker', add the search directory of the libraries if needed. On Linux Ubuntu, the external libraries are always stored in standard system directories. The local library ‘{\em libbasic\_lib}’ library can be stored in any location, for example \url{~/comp_models/basic}. For this, click the Add button, then click (\ldots) and navigate to the appropriate directory.  

 
\end{enumerate}




\item
Build the project, which translates the SCL source file, compiles, and links the files in the project. On the top bar, select the Build menu and select the Build option. The Build log appears in the lower pane of the Codeblocks screen and is shown in Figure~\ref{fig:cb_build}.

\begin{figure}[H]
\centering
\includegraphics[width=4.7in]{figs/wel_build.png}
\caption{Building the project.}
\label{fig:cb_build}
\end{figure}

\item
To execute the program, select the Run option in the Build menu. A new screen appears with the results of the execution, as shown in Figure~\ref{fig:cb_welrun}. After the program terminates execution, press the Enter key.

\begin{figure}[H]
\centering
\includegraphics[width=4.25in]{figs/CB_wel_Run.png}
\caption{Executing the project.}
\label{fig:cb_welrun}
\end{figure}

\item
On the top bar, activate the File menu and select Close project. Because the project was created in the directory  \url{~/comp_models/scl_models}, Codeblocks creates several new directories and the executable file in located in the directory  \url{~/comp_models/scl_models/Welcome/bin/Debug}.

\end{enumerate}
\end{document}
