Programming for Linux


In this article you will discover differences in programming for Linux platform with Nitisa framework. As you will see there are almost none.



Introduction

Linux operating systems are different from Windows. They lack many features Windows has. For instance, there are no any standard dialogs to select color, setup font, printing, and so on. Even creating simple true modal dialog window for the application is not possible for Linux. Moreover, all linuxes are different. If something work on one of them it doesn't mean it will work on another one. There is always at least one Linux implementation which works in the way you completely could not predict. We have been trying to achieve as much as possible having the limited set of tools on Linux and are going to try implementing missing features by our own to provide you with powerfull and easy to use instruments to create GUI applications on Linux systems as well.

To develop applications using Nitisa framework for Linux platforms you have first install on the Linux machine some packages Nitisa depends on. You can find the list in the requirements article.

Platform classes for Linux of the Nitisa framework work with X11 subsystem, which is available on most Linux with graphical interface. If your Linux doesn't have it, the only way for you to get Nitisa work in this case is to implement platform dependent classes for your Linux from scratch.

Code

Despite all the limitations of the Linux operating systems we made it possible for you to write code as much the same as on the Windows. The only difference is project settings and platform dependent file locations. So, lets compare them.

Linux

#include "Standard/Platform/Linux/Application.h" // All platform dependent classes are located in the "Standard/Platform/Linux" folder and subfolders 
...
int main()
{
    nitisa::standard::linux::CApplication app; // All platform dependent classes are located in the "nitisa::standard::linux" namespace and namespaces inside 
    app.CreateForm(&form);
    app.setMainForm(form);
    app.Run();
    return 0;
}

Windows

#include "Standard/Platform/Windows/Application.h" // All platform dependent classes are located in the "Standard/Platform/Windows" folder and subfolders 
...
int main()
{
    nitisa::standard::windows::CApplication app; // All platform dependent classes are located in the "nitisa::standard::windows" namespace and namespaces inside 
    app.CreateForm(&form);
    app.setMainForm(form);
    app.Run();
    return 0;
}

As you can see the difference is really small. If you create crossplatform application you really can use the same source code for all platforms just in rare cases selecting between correct namespace which can easily be achived using preprocessor.

Debugging

If you develop your linux application in Visual Studio and use another Linux machine(either real or virtual one) you might want to debug your application using its great debugging features. Sure you can try to do it and it will work fine for console applications but it won't work for graphical ones. That is because Visual Studio connects to remote machine via ssh and thus there is no graphical subsystem in this case. It means no window can be created and thus application with modern GUI cannot be properly started. Anyway, if it could you would not see anything as there is no such possibility in using Visual Studio with Linux. So, if you want to debug GUI application built with Nitisa framework for Linux platform, you have to use some debugger directly on Linux machine. For example, you can use gdb.

When using real, not virtual one, machine with Linux, you usually won't have any trouble. But many developers have only one PC and use virtual ones. That is okay. You still may develop and debug applications with Nitisa using virtual machine(VM). But you need to know there could be trouble with linking. In many cases required library libGL.a is missing on virtual machines. To solve this you may link with libGL.so.1 instead(number can be different depending on you Linux installation; we hope you know where to search). To do this you have to change the OpenGL input library in project settings like shown below.

Linking with specific library in Linux project

All virtual machines support only a very old OpenGL features(for the moment of writing of this article(2020 year) the maximum known supported OpenGL version was 3.3). The Nitisa Linux OpenGL renderer from Standard package requires at least OpenGL 4.3. Fortunately there is still a way to run such applications and see them properly drawing all your GUI forms. To achieve this you can use Mesa 3D library version override and software rendering features. All you need is to run your application using command MESA_GL_VERSION_OVERRIDE=4.3 MESA_GLSL_VERSION_OVERRIDE=400 LIBGL_ALWAYS_SOFTWARE=true ./YourApplicationName.out. The rendering may be very slow, especially first time. You have to be patient. On some virtual machines first rendering appeared only after a minute or two but next ones were very fast in our tests.