KDevelop5/Manual/Building (compiling) projects with custom Makefiles/da: Difference between revisions

From KDE UserBase Wiki
(Importing a new version from external source)
(Importing a new version from external source)
Line 7: Line 7:
{{Note/da|1='''KDevelop''' 4.x kender ikke til '''GNU autotools''' mens dette skrives. Hvis dit projekt bruger dem, så bliver du selv nødt til at køre <code>./configure</code> eller andre relaterede kommandoer på en kommandolinje. Hvis du ønsker at gøre dette inde fra '''KDevelop''', så åbn værktøjet '''Konsole''' (føj det til hovedvinduets kant om nødvendigt ved at vælge menuen <menuchoice>Vindue -> Tilføj værktøjsvisning...</menuchoice>); det giver dig en skalvinduesvisning. Kør så <code>./configure</code> på kommandolinjen i denne visning.}}
{{Note/da|1='''KDevelop''' 4.x kender ikke til '''GNU autotools''' mens dette skrives. Hvis dit projekt bruger dem, så bliver du selv nødt til at køre <code>./configure</code> eller andre relaterede kommandoer på en kommandolinje. Hvis du ønsker at gøre dette inde fra '''KDevelop''', så åbn værktøjet '''Konsole''' (føj det til hovedvinduets kant om nødvendigt ved at vælge menuen <menuchoice>Vindue -> Tilføj værktøjsvisning...</menuchoice>); det giver dig en skalvinduesvisning. Kør så <code>./configure</code> på kommandolinjen i denne visning.}}


The first step is to teach '''KDevelop''' about targets in your Makefiles. There are two ways to do that: selecting individual Makefile targets, and choosing a set of targets you may want to build frequently. For both approaches, open
Det første skridt er at lære '''KDevelop''' om mål i dine Makefiler. Der er to måder at gøre det på: du kan angive individuelle Makefile-mål og du kan vælge en gruppe af mål, som du ofte vil bygge. Til begge fremgangsmåder åbnes værktøjet '''Projekter''' ved at klikke på knappen <menuchoice>Projekter</menuchoice> i hovedvinduets kant (se ovenfor, hvordan du tilføjer knappen, hvis den ikke allerede er der). Værktøjsvisningen '''Projekter''' har to dele: den øverste halvdel med titlen '''Projekter''' indeholder en liste med alle dine projekter og lader dig udvide det underliggende mappetræ. Den nederste del med titlen '''Projektvalg''' indeholder en liste med de projekter, som vil blive bygget, hvis du vælger menuen <menuchoice>Projekt -> Byg valgte</menuchoice> eller taster <keycap>F8</keycap>. Dette kommer vi tilbage til nedenfor.
the '''Projects''' tool by clicking on the <menuchoice>Projects</menuchoice> button on the perimeter of '''KDevelop's''' main window (if you don't have this button see above how to add a tool's button there). The '''Projects''' tool window has two parts: the top half &mdash; titled '''Projects''' &mdash; lists all of your projects and let's you expand the underlying directory trees. The bottom half &mdash; titled '''Project Selection''' &mdash; lists a subset of those projects that will be built if you choose the menu item <menuchoice>Project -> Build selection</menuchoice> or hit <keycap>F8</keycap>; we'll come back to this part below.
<span id="Building individual Makefile targets"></span>
<span id="Building individual Makefile targets"></span>
=== Building individual Makefile targets ===
=== Building individual Makefile targets ===

Revision as of 08:07, 1 October 2017

Other languages:

Byg (kompilér) projekter med dine egne makefiler

Mange projekter beskriver, hvordan kildefiler skal kompileres (og hvilke filer, der skal kompileres når en kilde- eller headerfil ændres) i Makefiler, som fortolkes af programmet make (se for eksempel GNU make). For enkle projekterer det ofte ret let at lave sådan en fil i hånden. Større projekter integrerer ofte deres makefiler med GNU autotools (autoconf, autoheader, automake). I dette afsnit vil vi simpelthen antage at du har en Makefile til dit projekt og vil lære KDevelop at arbejde sammen med den.

Note

KDevelop 4.x kender ikke til GNU autotools mens dette skrives. Hvis dit projekt bruger dem, så bliver du selv nødt til at køre ./configure eller andre relaterede kommandoer på en kommandolinje. Hvis du ønsker at gøre dette inde fra KDevelop, så åbn værktøjet Konsole (føj det til hovedvinduets kant om nødvendigt ved at vælge menuen Vindue -> Tilføj værktøjsvisning...); det giver dig en skalvinduesvisning. Kør så ./configure på kommandolinjen i denne visning.


Det første skridt er at lære KDevelop om mål i dine Makefiler. Der er to måder at gøre det på: du kan angive individuelle Makefile-mål og du kan vælge en gruppe af mål, som du ofte vil bygge. Til begge fremgangsmåder åbnes værktøjet Projekter ved at klikke på knappen Projekter i hovedvinduets kant (se ovenfor, hvordan du tilføjer knappen, hvis den ikke allerede er der). Værktøjsvisningen Projekter har to dele: den øverste halvdel med titlen Projekter indeholder en liste med alle dine projekter og lader dig udvide det underliggende mappetræ. Den nederste del med titlen Projektvalg indeholder en liste med de projekter, som vil blive bygget, hvis du vælger menuen Projekt -> Byg valgte eller taster F8. Dette kommer vi tilbage til nedenfor.

Building individual Makefile targets

In the top part of the project view, expand the sub-tree for one project, let's say the one for which you want to run a particular Makefile target. This will give you icons for (i) directories under this project, (ii) files in the top-level directory for this project, (iii) Makefile targets KDevelop can identify. These categories are shown in the picture at right. Note that KDevelop understands Makefile syntax to a certain degree and therefore can offer you targets defined in this Makefile (though this understanding has its limits if targets are composed or implicit).

To build any of the targets listed there, click on it with the right mouse button and select Build. For example, doing this with the "clean" target will simply execute "make clean". You can see this happening in the subwindow titled Build that opens up, showing the command and the output. (This window corresponds to the Build tool, so you can close and later re-open the window using the Build tool button on the perimeter of the main window. It is shown at the bottom right of the picture.)

Selecting a collection of Makefile targets for repeated building

Right-clicking on individual Makefile targets every time you want to build something will quickly get old. Rather, we'd like to have individual targets for one or more of the projects in the session that we can repeatedly build without much mouse work. This is where the concept of "Build target selections" comes in: it is a collection of Makefile targets that are built one-after-the-other whenever you hit the Build selection button in the button list at the top, select the Project -> Build selection menu item, or hit the F8 function key.

The list of selected Makefile targets is shown in the bottom half of the Projects tool view. By default, the selection contains all projects, but you can change that. For example, if your list of projects contains three projects (a base library L and two applications A and B), but you're currently only working on project A, then you may want to remove project B from the selection by highlighting it in the selection and hitting the button. Furthermore, you probably want to make sure that the library L is built before project A by moving entries in the selection up and down using the buttons to the right of the list. You can also get a particular Makefile target into the selection by right-clicking onto it and selecting Add to buildset, or just highlighting it and hitting the button just above the list of selected targets.

KDevelop allows you to configure what to do whenever you build the selection. To this end, use the menu item Project -> Open configuration. There, you can for example select the number of simultaneous jobs "make" should execute — if your computer has, say, 8 processor cores, then entering 8 in this field would be a useful choice. In this dialog, the Default make target is a Makefile target used for all targets in the selection.

What to do with error messages

If the compiler encounters an error message, simply click on the line with the error message or use Navigation - Jump to Next Outputmark item in the main menu and the editor will jump to the line (and if available column) where the error was reported. Depending on the error message, KDevelop may also offer you several possible actions to fix the error, for example by declaring a previously undeclared variable if an unknown symbol was found.