Copie du wikimiroir

Ceci est un miroir du wiki de pascal.chat. La modification, l’historique et la connexion se trouvent là-bas.

Unit not found - How to find units/fr

Deutsch · English · Français · Magyar

Vue d'ensemble

Cette page est à propos d'une des plus proéminantes erreurs de pascal: unité non trouvée ou ne peut pas trouver l'unité. Cette erreur a beaucoup de raisons et cette page essaye de recueillir la plupart des raisons, comment découvrir , quel problème c'est, et comment le résoudre .

Notations, termes

Étape 1: Compilateur ou IDE ou tous les deux

La première étape est de découvrir , si l'IDE ne peut pas trouver l'unité, ou le compilateur ne peut pas la trouver ou les deux .

Bien que le compilateur et l'IDE emploient les algorithmes tout à fait semblables de recherche pour trouver une unité , il y a quelques différences . C'est pourquoi parfois l'IDE peut trouver une unité, que le compilateur ne peut pas et vice versa. Si le compilateur ne peut pas la trouver, la compilation échoue (Construire, Ctrl+F9) avec l'erreur 'unit not found'. Si l'IDE ne peut la pas trouver, les outils de code échoueront. Par exemple Find Declaration (Alt+Up ou les bouttons de la sourie Ctrl+Left) ou Identifier completion (Ctrl+Space) échoueront avec la même erreur 'unit not found'.

En commun :

text
 1. Unit1.pp
 2. unit1.pp
 3. UNIT1.PP
 4. Unit1.pas
 5. unit1.pas
 6. UNIT1.PAS

Ils sont recherchés dans chaque répertoire du chemin de recherche.

Différences :

Cas 1: Tous les deux ne peuvent pas trouver une unité

Case 2: Compiler finds a unit, but IDE does not

The next sub cases assumes, that Run -> Build (Ctrl+F9) in the Lazarus IDE works, but Find Declaration fails with the error: unit not found. If unsure, check Case 1 as well.

Case 3: IDE finds a unit, but compiler does not

This is the case, when Find Declaration finds the unit, but building (Ctrl+F9) fails.

There are two cases: Either the compiler didn't find anything, or it does not like, what it found. In both cases it returns the same error: unit xyz not found.

Case 3.1: The compiler finds the .ppu file, but does not like it

This can happen, when the found .ppu file is older than a required unit (.pas, .pp or .ppu). For example if unit1 uses unit2 and unit2 was changed, then unit1 needs to be recompiled as well.

It can also happen, if you installed newer files without deleting the old ones. The compiler stops at the first found.

You can see, what the compiler finds and what is missing by giving the -vt command line switch. But this gives a lot of output and it is hard to read for newbies.

The easiest way is often to first recompile the packages and project clean (Build all). In case of the Lazarus sources itself: The configure build lazarus dialog has a button to setup all options for a clean build.

Case 3.2: The compiler does not find neither source (.pas, .pp) nor .ppu file

In this case you have to extend the search path. The question is: Adding the .ppu directory or the source directory?

WARNING: If you add the wrong search path, it can happen, that the compiler will create multiple copies of files and you will later get the 'unit not found' error of Case 3.1.

Many projects and packages have distinct source directories (.pas, .pp) and output directories (.ppu). If a package has an output directory, then only this directory should be added to the search path of any depending project and/or package. The IDE will do this automatically. For example: Adding the LCL as dependency to your project adds two output directories to your unit search path. You can see this in Compiler Options -> Inherited. Never add any other LCL directory to your search paths or you will get Case 3.1 errors.


From the Free Pascal wiki, page "Unit not found - How to find units/fr", as it stood on 2007-06-25 after a change by Paulatreides, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Version 2, dernière modification par WikiArchive .