Das K Desktop Environment

3.2. The First Build

After our project is generated, we'll first make a trip through the source code to get a general understanding how the application frame works. This won't only help to get started but we'll know where to change what in later steps.

When opening the LFV (Logical File Viewer) page on the tree-view, you see some folders that already sort the project files relevant to the developer. The first two folders are "Header" and "Sources". The Header-folder therefore logically contains all header files of the project, the Sources-folder all sourcecodes. All other folders are of no interest right now, so we'll turn back here later to see what they contain.

The two folders then contain the following files:

Headers:

Sources:

Before diving into the sources, we'll let KDevelop build and run our new application. To do this, select "Make" from the "Build"-menu or hit the according button on the toolbar . The output window opens from the bottom of KDevelop and lets you see what make does by the messages it gives us:

 1   Making all in docs
 2   make[1]: Entering directory `/home/rnolden/Tutorial/kscribble1/kscribble/docs'
 3   Making all in en
 4   make[2]: Entering directory `/home/rnolden/Tutorial/kscribble1/kscribble/docs/en'
 5   make[2]: Nothing to be done for `all'.
 6   make[2]: Leaving directory `/home/rnolden/Tutorial/kscribble1/kscribble/docs/en'
 7   make[2]: Entering directory `/home/rnolden/Tutorial/kscribble1/kscribble/docs'
 8   make[2]: Nothing to be done for `all-am'.
 9   make[2]: Leaving directory `/home/rnolden/Tutorial/kscribble1/kscribble/docs'
 10  make[1]: Leaving directory `/home/rnolden/Tutorial/kscribble1/kscribble/docs'
 11  make[1]: Entering directory `/home/rnolden/Tutorial/kscribble1/kscribble'
 12  g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/opt/kde/include -I/usr/lib/qt/include  -I/usr/X11R6/include    -O0 -g -Wall  -c
     kscribbleview.cpp
 13  g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/opt/kde/include -I/usr/lib/qt/include  -I/usr/X11R6/include    -O0 -g -Wall  -c
     kscribbledoc.cpp
 14  g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/opt/kde/include -I/usr/lib/qt/include  -I/usr/X11R6/include    -O0 -g -Wall  -c 		
     kscribble.cpp
 15  g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/opt/kde/include -I/usr/lib/qt/include  -I/usr/X11R6/include    -O0 -g -Wall  -c
     main.cpp
 16  /usr/bin/moc ./kscribble.h -o kscribble.moc.cpp
 17  g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/opt/kde/include -I/usr/lib/qt/include  -I/usr/X11R6/include    -O0 -g -Wall  -c
     kscribble.moc.cpp 		
 18  /usr/bin/moc ./kscribbledoc.h -o kscribbledoc.moc.cpp
 19  g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/opt/kde/include -I/usr/lib/qt/include  -I/usr/X11R6/include    -O0 -g -Wall  -c
     kscribbledoc.moc.cpp
 20  /usr/bin/moc ./kscribbleview.h -o kscribbleview.moc.cpp
 21  g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/opt/kde/include -I/usr/lib/qt/include  -I/usr/X11R6/include    -O0 -g -Wall  -c
     kscribbleview.moc.cpp
 
 22  /bin/sh ../libtool --silent --mode=link g++  -O0 -g -Wall   -o kscribble -L/opt/kde/lib  -L/usr/X11R6/lib -rpath /opt/kde/lib
     -rpath /usr/X11R6/lib kscribbleview.o kscribbledoc.o kscribble.o main.o kscribble.moc.o kscribbledoc.moc.o kscribbleview.moc.o
     -lkfile -lkfm -lkdeui -lkdecore -lqt -lXext -lX11
 
 23  make[1]: Leaving directory `/home/rnolden/Tutorial/kscribble1/kscribble'

As you see, we've put line numbers in front of each line, which won't appear in your output; it just makes it easier to describe what happened during the build now. First of all, make works recursively. That means, it starts from the directory it is invoked in and then goes into the subdirectories first, returns and processes the next directory. Finally, the directory it was started is processed and make finishes. Therefore, make started in the main project directory containing the sources first. In line 1 and 2, you see how the make process goes into the docs directory, then into the en subdirectory. As there isn't anything to do, it leaves these directories until it returns to the source-directory kscribble in line 11. Then, the real work starts: make invokes the compiler, here g++ to compile the source-file kscribbleview.cpp. The macro -DHAVE&_;CONFIG&_;H says that the file config.h should be used. This is a file containing macros for the specific platform and application and is located in the main project directory. The following -I commands add the include path where g++ can find the includes it needs. These are the current directory, the main project directory (by -I..) and the include path for the KDE, Qt and X11 library header files. The directories for these include files were determined by the configure script and set in the Makefiles, therefore, the compiler knows where these are located. Finally, -O0 sets the optimization to zero (no optimization), -g enables debugging, -Wall sets the compiler warnings to all and -c tells the compiler to produce an object file, so only compile the file.

This is done for the other source files of our project as well in lines 13-15. Obviously, our sources are compiled, but instead of linking the object files of the sources to the final binary, we see some other commands. In line 16, you see that the program "moc" is called to process the header file kscribble.h, with its output in kscribble.moc.cpp. Then, in line 17, this source file is compiled as well. The same happens with the other project header files until line 21. Now, as the Qt toolkit contains the signal/slot mechanism, but still stays a C++ implementation, you're using certain keywords that are not originally C++ language, such as the signals: and slots: declaration in your classes. This gives you the ability to easily allow object communication for all class objects that inherit the class QObject, so you can avoid the usual callback pointer functions. Therefore, the application needs the sources that implement this functionality, and that is why moc is called. Moc is the Meta Object Compiler of the Qt toolkit and builds the implementation for signals and slots mechanisms by parsing the header file and producing a source output that has to be compiled in the binary. As KDevelop projects use automoc to determine, which header file needs to be processed, you don't have to take care for any call on moc and the C++ compiler on the moc output files. Just remember the rules that make a class use the signals and slots- inheritance from QObject or any class that inherits QObject itself, inclusion of the Q&_;OBJECT macro (without semicolon !) at the beginning of the class declaration and the declarations for signals and slots.

Finally, your binary is built by the compiler. The output binary is called kscribble, the linker includes the path for the KDE and X11 libraries and links the sources against the libraries kfile, kfm, kdeui, kdecore, qt, Xext and X11. Then you're done and make exits.