Archive:Getting Started/Set up KDE 4 for development (zh CN): Difference between revisions

From KDE TechBase
m (New page: {{Template:I18n/Language Navigation Bar|Getting_Started/Set_up_KDE_4_for_development}} {{TutorialBrowser| series=开始| name=Set up KDE 4 for development| pre=[[Getting_Started/Build/...)
 
No edit summary
Line 1: Line 1:
 
<!--Huwei初稿--!>
{{Template:I18n/Language Navigation Bar|Getting_Started/Set_up_KDE_4_for_development}}
{{Template:I18n/Language Navigation Bar|Getting_Started/Set_up_KDE_4_for_development}}
{{TutorialBrowser|
{{TutorialBrowser|
Line 5: Line 5:
series=开始|
series=开始|


name=Set up KDE 4 for development|
name=为后续开发设置KDE 4|


pre=[[Getting_Started/Build/KDE4|Build KDE 4]]|
pre=[[Getting_Started/Build/KDE4|Build KDE 4]]|
Line 13: Line 13:
}}
}}


{{note|This page assumes you have built kdelibs, kdepimlibs, and kdebase according to [[Getting Started/Build/KDE4|these]] instructions}}
{{note|本文假定您已经基于 [[Getting Started/Build/KDE4|从源代码构建KDE4]] 的介绍成功构建了kdelibs、kdepimlibs和hdebase}}


== Launching KDE 4 apps & sessions ==
== Launching KDE 4 apps & sessions ==

Revision as of 06:27, 13 November 2007


Setting up KDevelop

Now that KDevelop has started, you need to adjust a few settings. Go to Settings->Configure KDevelop...->Documentation for this. Remove all entries that are not relevant to KDE 4 coding.

Note
Although environment variables like $HOME are used in this section, you should replace them with real paths because KDevelop does not resolve environment variables.


Now click Add... to add the kdelibs API documentation. In this dialog, use the following settings:

  • Type: Doxygen Documentation Collection (needs to be set first)
  • Location: $KDE_SRC/KDE/kdelibs/kdelibs-apidocs/index.html

Now add the Qt API documentation, using the following settings:

  • Type: Qt Documentation Collection (needs to be set first)
  • Location: $HOME/qt-copy/doc/html/qt.dcf

After you have added kdelibs and Qt API documentation, make sure all checkboxes (TOC,Index and Search) are enabled. Then, go to the Full Text Search tab and make sure the paths to the htdig, htmerge and htsearch executables are correct. You can then close the settings dialog.

Now it is time to open the project you want to work on by clicking Project->Open Project.... The project files are located in the directory. For example, if you want to work on Konsole, you need to open $KDE_BUILD/KDE/kdebase/apps/konsole/konsole.kdevelop. You now need to adjust a few project-specific settings in Project->Project Options. You need to do this every time you start to work on a different project.

Note
Sometimes, a KDevelop project file is not present for the folder you want to work on.

This can have several reasons, it depends on how the CMake files are written. Usually, CMake files which have a project(projectname) statement in them should work fine. Once you are familiar enough with CMake, you can try adding the statement.

A workaround for this is to simply use the KDevelop project file of the parent folder, or even higher. In this case, you need to use the Make Active Directory entry in the context menu of the File Selector sidetab. With this, you can ignore the other unwanted folders when building and installing.


  • C++ Support->Code Completion
Here you need to add code completion databases for Qt and kdelibs, and more if you like, for example you might need a database for kdepimlibs when working on kdepim.
For kdelibs, click the Add... button and choose KDevelop Custom Directory PCS Importer, then add your KDE include directory ($HOME/kde/include) to the list and proceed. You can use the file selection dialog and the Add button to add it.
Now, add the database for Qt 4 by selecting KDevelop Qt4 PCS Importer this time. You need to select the Qt 4 include directory, which is $HOME/qt-copy/include.
Note
The Qt4 PCS Importer is only needed if you didn't install Qt4, i.e. you use it directly from the build directory. The drawback of using the Qt4 importer is that it doesn't show progress and the application seems to hang while it imports. The alternative is to use the Custom Directory PCS Importer for this too


  • C++ Support->Qt Options
Check Enable Qt options and choose Qt4 as your version. Set the QMake Binary path to $HOME/qt-copy/bin/qmake. Then choose Qt 4 style as Qt include syntax. Use $HOME/qt-copy/bin/designer as Designer Binary. Make sure to use the Change Plugin Paths dialog to add the plugin directory from KDE so you see the KDE widgets when designer is started. To do this add $HOME/kde/lib/kde4/plugins to the lineedit and then click the Add button.
  • Run Options
Make sure you use the correct binary as Executable. For example, if you want to run Konsole, this is $KDE_BUILD/KDE/kdebase/apps/konsole/src/konsole. You should add --nofork to the Debug Arguments or debugging some applications like KMail will not work at all.
Because the start3app functions changes some environment variables, you need to change them back here so the KDE 4 applications can be run without problems from within KDevelop.
For some applications, like Konsole, this is not strictly necessary, but others like KMail will crash if you do not change this.
Simply click the Add / Copy button to add new environment variables. You will need the following, which are the same as in your .bashrc:
Name Value
KDEHOME $HOME/.kde4
PATH $QTDIR/bin:$KDEDIR/bin:/usr/local/bin:$PATH
LD_LIBRARY_PATH $QTDIR/lib:$KDEDIR/lib:$LD_LIBRARY_PATH
KDETMP /tmp/$USER-kde4
KDEVARTMP /var/tmp/$USER-kde4
KDEDIR $HOME/kde
KDEDIRS $KDEDIR
LD_BIND_NOW 42


  • Build Options->Build
Make sure the correct build directory is selected. Again, for Konsole, this would be $KDE_BUILD/KDE/kdebase/apps/konsole.
  • Build Options->Make
You might want to check Abort on first error. You also might want to add VERBOSE= or VERBOSE=1 to Additional make options to control the level of verbosity for the build process.
If you have more than one processor or if you have access to an icecream cluster, you might want to check the Run multiple jobs option and set the Number of simultaneous jobs to the number of available processors. This increases the compile speed. It is the same as the -j option for make.
  • Formatting
You should set all options here to match the coding style of the project you are working on.
  • CTags->General
You need to correctly set the Path to ctags binary, which is /usr/bin/ctags on Debian-based systems.
You probably want to enable the When more than one hit, go directly to the first option.

Now you have finished adjusting your project-specific settings. Now you should remove some plugins you do not need, in Settings->Configure Plugins.... I for example disable the following plugins:

Abbreviation Expansion, Code Snippets, Doxygen Support, Embedded Konsole, File Tree, Final Packaging Support, "Open with" Menu Addon, QuickOpen, Regular Expression Tester, Scripting, Security Checker, Shell Filtering and Insertion, Text Structure and Tools Menu Addition.

You should at least disable the bold ones.

Now, open any source file if none is open already. This will enable the Settings->Configure Editor... entry, where you need to set the tab options to match the tab style used by the project you are working on. The important settings are:

  • Appearance->Borders->Show line numbers: Should be checked.
  • Appearance->Borders->Show icon border: Should be checked.
  • Editing->Tabulators
  • Editing->Static Word Wrap->Show marker: Should be checked
  • Indentation->Automatic Indentation->Indentation mode: Should be C Style
  • Indentation in general

In the mainwindow, click the CTags tab on the bottom tabbar, then click the Regenerate button to create a CTags database for easier source code navigation.

Now you have completed all essential configuration, congratulations!

Using KDevelop

Refer to the KDevelop manual for general help using KDevelop. The following section will only deal with special cases for KDE 4.

Debugging

KDE apps have many symbols, which means that you need a lot of memory to get a decent loading times for debugging. To quote a GDB developer: "I would be reluctant to debug KDE on something with <1GB RAM." If the stepping function of the debugger is slow for you, try the following tips:

  • Hide local variables. The Locals part of the variable tab on the left causes a big slowdown when stepping if you have many local variables. Simple collapse the Locals part of the tree, the local variables are then not updated every step. You can still examine variables by using the Evaluate expression function.
  • Use the patch at http://bugs.kde.org/show_bug.cgi?id=143977. It prevents the update of the framestack widget at each step, speeding up stepping considerably. The patch introduces some minor glitches, which is why it is not yet commited.
Note
KDevelop does not yet support modifing the CMake build system. This means you can not use KDevelop to add or remove files from the project or to change any other aspect of your project's build process. You need to modify the CMake files by hand and then rerun cmakekde instead. Read the CMake tutorial to learn how to do this.


Tip
When you work on libraries, you first need to install them before you can test or debug your changes.

Since this is cumbersome and time consuming, you should create symlinks (ln -s) pointing from the build directory to the installation directory for all affected libraries.

Often, even simple programs use libraries internally, for example the settings dialog of Konsole is really a library.