Unit not found - How to find units

From Lazarus wiki
Jump to navigationJump to search

Overview

This page is about one of the most prominent errors of pascal: unit not found. This error has a lot of reasons and this page tries to gather most of the reasons, how to find out, which problem it is, and how to solve it.

Step 1: Compiler or IDE

The first step is to find out, if the IDE can not find the unit, or the compiler can not find it or both.

Although the compiler and the IDE are using quite similar search algorithms to find a unit, there are some differences. That's why sometimes the IDE can find a unit, which the compiler can not and vice versus. If the compiler can not find it, the compilation fails (Build, Ctrl+F9) with the error 'unit <xxx> not found'. If the IDE can not find, the code tools will fail. For example Find Declaration (Alt+Up or Ctrl+Left mouse button) or Identifier completion (Ctrl+Space) will fail with the same error 'unit <xxx> not found'.

Common:

  • Both search units in the search path.
  • Both search first for pascal sources (.pas, .pp) files. Under MacPAS mode: search for .p files too.
  • Both search for several cases: normal case, lower case, upper case. For example: if the uses section contains 'Unit1', then it searches:
 1. Unit1.pp
 2. unit1.pp
 3. UNIT1.PP
 4. Unit1.pas
 5. unit1.pas
 6. UNIT1.PAS

They are searched in every directory of the search path.

Differences:

  • FPC uses the fpc.cfg for additional search paths. The IDE uses them only to find files