Difference between revisions of "Lazarus FAQ"

From Lazarus wiki
Jump to navigationJump to search
(more elaborate clarification commercial plug-in)
 
(304 intermediate revisions by 77 users not shown)
Line 1: Line 1:
 
{{Lazarus Faq}}
 
{{Lazarus Faq}}
 +
{{Note|This FAQ may be '''outdated''' in certain parts.}}
 +
== General ==
 +
=== What is Lazarus? ===
 +
Lazarus is a cross-platform integrated development environment (IDE) that lets you create visual (GUI) and non-visual Object [[Pascal]] programs, and uses the Free Pascal compiler to generate your executable. Its aim is ''write once, compile anywhere'': you should be able to just recompile your program source code with Lazarus running on another operating system (or a cross compiler) and get a program that runs on that operating system.
 +
 +
For more details see [[Overview of Free Pascal and Lazarus]]
 +
 +
=== Why are the generated binaries so big? ===
 +
The binaries are big because they include a lot of debug information necessary for using gdb (GNU Debugger).
 +
A debugger is a program that is used to test your code. It uses the extra-information stored in your binary to test it. But once your program is working well, you may delete those infos and reduce the size of the binary.
 +
 +
'''Quick guide to Lazarus/FPC application size reduction'''
 +
* 1. Project|Compiler Options|Code|Smart Linkable (-CX) -> Checked
 +
* 2. Project|Compiler Options|Linking|Debugging| Uncheck all except Strip Symbols From Executable (-Xs)
 +
* 3. Project|Compiler Options|Linking|Link Style|Link Smart (-XX) -> Checked
 +
{{Note| only do this if you don't need to run the debugger. For more details, see [[Size Matters]]}}
 +
 +
Lazarus executable size starts big, but grows very slowly, because of the way the LCL is designed, and its use of certain Free Pascal features (RTTI). Projects that don't use the LCL are much smaller (this is similar to some non-GUI C++ frameworks). This typically requires more manual coding though.
 +
 +
'''Exclude image readers'''
 +
See [[Lazarus 1.10.0 release notes#LCL Changes]]
 +
If your app does not use images compressed in one of those formats, then you can exclude it.
 +
 +
=== Do I need ppc386.cfg or fpc.cfg? ===
 +
You only need fpc.cfg. This way the compiler knows where to find the libraries.
 +
 +
=== How do I compile Lazarus? ===
 +
Do something like this:
 +
<syntaxhighlight lang="bash">cd lazarus
 +
make clean all</syntaxhighlight>
 +
 +
If you want to build Lazarus for different widgetset eg. Qt (supported on Linux, Windows and OSX) then use the LCL_PLATFORM argument:
 +
<syntaxhighlight lang="bash">cd lazarus
 +
make clean all LCL_PLATFORM=qt</syntaxhighlight>
 +
 +
=== Is it possible to build Lazarus projects without the Lazarus IDE? ===
 +
See [[Using_the_LCL_without_Lazarus]]
 +
 +
=== How do I build other Free Pascal programs that use LCL without the Lazarus IDE? ===
 +
See [[Using_the_LCL_without_Lazarus]]
 +
 +
=== What version of FPC is required? ===
 +
Any Lazarus version compiles and works with 2 latest FPC release versions. FPC release cycle is slow and 2 latest versions typically span over few years.
  
This FAQ is being copied from the FAQ at www.freepascal.org, as this wiki document is easier to maintain and extend.
+
Lazarus trunk also supports FPC trunk.
  
== General ==
+
* Lazarus 1.0.8 requires at least FPC 2.6.2.
 +
* Lazarus 1.0 requires at least FPC 2.6.0.
 +
* Lazarus 2.x requires at least FPC 3.0.0
 +
* Lazarus 3.0 requires at least FPC 3.2.0
 +
 
 +
=== I can't compile Lazarus ===
 +
# Check if the compiler is the correct version
 +
# Check if the (fpc) libraries are from the same version
 +
# Check if the compiler installation path has spaces in it. Make sure it doesn't!
 +
# Check if you have a fpc.cfg and no old ppc386.cfg
 +
# Check also the OS-dependent FAQs
 +
# If you're still stuck, ask on the forum or Lazarus mailing list
 +
 
 +
=== How to embed a small file in the executable, without the need of a separate file? How to embed a resource? ===
 +
Both Lazarus resource and Windows-type/FPC resources are supported. See [[Lazarus Resources]].
 +
 
 +
=== What is the meaning of the various file extensions used by Lazarus? ===
 +
The [[Lazarus Tutorial#The Lazarus files]] explains some extensions by an example.
 +
Here is a brief list:
 +
 
 +
{| class="wikitable sortable"
 +
|-
 +
! extension !! filetype || description
 +
|-
 +
| <code>.lpi</code> || Lazarus&#160;Project&#160;Information || contains project-specific settings like compiler settings and needed packages. stored in XML
 +
|-
 +
| <code>.lps</code> || Lazarus Program Session || Personal data like cursor positions, source editor files, personal build modes. stored in XML
 +
|-
 +
| <code>.lpr</code> || Lazarus Program || Pascal source of main program.
 +
|-
 +
| <code>.lfm</code> || Lazarus Form || Form configuration information for all objects on a form (stored in a Lazarus-specific textual format, similar to Delphi dfm; the actions are described by Pascal source code in a corresponding <code>*.pas</code> file)
 +
|-
 +
| <code>.pas</code> <br /> <code>.pp</code> <br /> <code>.p</code> || Pascal code || Pascal code typically for a form stored in a corresponding <code>*.lfm</code> file
 +
|-
 +
| <code>.lrs</code> || Lazarus Resource || Generated Lazarus Resource file; not to be confused with a Windows resource file.
 +
This file can be created with lazres tool (in directory Lazarus/Tools) using commandline: lazres myfile.lrs myfile.lfm
 +
|-
 +
| <code>.ppu</code> || Compiled unit || Compiled source code created by the Free Pascal compiler for each unit and program.
 +
|-
 +
| <code>.o</code> || Object file || created by the compiler, every ppu file has a corresponding o file, needed by the linker.
 +
|-
 +
| <code>.lpk</code> || Lazarus package information || package-specific settings, like compiler settings and needed packages; stored in XML
 +
|-
 +
| <code>.lrt</code> || Lazarus&#160;Resourcestring&#160;table || Lazarus Resourcestring table created when saving a lfm file and i18n is enabled. It contains the TTranslateString properties of the lfm. Do not edit them, they are overwritten.
 +
|-
 +
| <code>.rst</code> || Resourcestring table || Resourcestring table created by the compiler for every unit with a resourcestring section. Do not edit them, they are overwritten.
 +
|-
 +
| <code>.po</code> || gnu gettext messages || When [[i18n]] is enabled the IDE creates/updated the .po files with the resourcestrings from the rst and lrt files.
 +
|}
 +
 
 +
=== Why are TForm.ClientWidth/ClientHeight the same as TForm.Width/Height ===
 +
The TForm.Width/Height do no include the frame, because there was no way to retrieve the frame size on all platforms. Without a reliable way, the LCL would move the forms around on the screen or resize them endlessly.
 +
 
 +
Eventually it will be changed when there is a reliable way to get the size and position of a window with its frame on all platforms. To keep compatibility with older LCL forms, a version number and some extra methods will be added.
 +
 
 +
== Errors ==
 +
Platform specific errors/problems are also covered in sections below.
 +
 
 +
=== 'Fatal: Circular unit reference between a and b' ===
 +
A common thing happened to a new user when one wants to create two forms referencing each other's properties. The error above only happens to uses clause of interface section, thus it's OK to put it in implementation section. Example:
 +
 
 +
This one causes error:
 +
<syntaxhighlight lang="pascal">
 +
unit a;
 +
 
 +
interface
 +
 
 +
uses b;
 +
 
 +
implementation
 +
 
 +
end.
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="pascal">
 +
unit b;
 +
 
 +
interface
  
=== Where can I find more FAQ? ===
+
uses a;
  
See the [http://www.lazarus.freepascal.org official website]. There is another FAQ as well.
+
implementation
  
===Why are the generated binaries so big?===
+
end.</syntaxhighlight>
The binaries are big because they include a lot of debug information necessary for using gdb (GNU Debugger).
 
  
The compiler has an option to remove the debug information from the executable (-Xs), but due to a bug in the compiler (version 2.0.2 and earlier), this doesn't work correctly. It has been fixed in the development version of the compiler.
+
But this one doesn't:
  
You can use a program called "strip" to remove the debug symbols from the executable file. It is located under lazarus dir lazarus\pp\bin\i386-win32\.
+
<syntaxhighlight lang="pascal">
 +
unit a;
  
Just type "strip --strip-all <your executable file with path>" on the command line.
+
interface
  
If you want to make your program even smaller, you should try [http://upx.sourceforge.net/ UPX] too. UPX is a very good exe compressor. It includes no memory overhead due to in-place decompression. It also has a very fast decompression (~10 MB/sec on an Pentium 133).
+
implementation
  
To use upx just type "upx <your executable file with path>" on the command line.
+
uses b;
  
after using both strip and upx a simple GUI Lazarus program gets:
+
end.
* ~ 700kb on Linux
+
</syntaxhighlight>
* ~ 420kb on Windows
 
  
A more detailed answer is given on [[Size Matters]].
+
<syntaxhighlight lang="pascal">
 +
unit b;
  
It's also important to note that the hello world lazarus software already includes a huge amount of features. It includes:
+
interface
  
* XML handling library
+
implementation
* Image handling library for png, xpm, bmp and ico files
 
* Almost all widgets from the Lazarus Component Library
 
* All of the Free Pascal Runtime Library
 
  
So it's very big, but it already includes almost everything a real world non-trivial app will need.
+
uses a;
  
Lazarus executable size starts big, but grows very slowly, because of the Free Pascal compiler and the way lazarus forms operate. A c++ project (just an example, but applies to other languages / tools too) starts very small on the hello world, but quickly grows exponentially when you need features to write a non-trivial application.
+
end.</syntaxhighlight>
  
[[Image:Lazarus_vs_cpp.png]]
 
  
=== Why is the linking so slow on Windows? ===
+
In some cases the '''minimal base class''' method might be suitable.
  
Generally speaking, compilation on Windows takes more time then other platforms because the GNU Linker utilized by Free Pascal is slow on this platform. This problem only affects Windows, and is only bad on relatively old computers (less then 1Ghz) and computers with little RAM (128MB or less).
+
Separate one class into a minimal base class (what the other needs) and derive it for the rest of the implementation.
  
Also, if you smartlink LCL the linking will be much slower. A study about this is located here: [[File size and smartlinking]]
 
  
A internal linker was developed, and is ready, but will only be available when Free Pascal 2.2 is released (of course it's also available via subversion). It decreases the linking time dramatically.
+
'''unita''': uses unitb
 +
<syntaxhighlight lang="pascal">
 +
  type
 +
    ClassA = class(BaseClassA)
 +
    // rest of ClassA
 +
    end;
 +
</syntaxhighlight>
 +
'''unitb''':
 +
<syntaxhighlight lang="pascal">
 +
  type
 +
    ClassB = class;  //forward declaration
  
'''Note''': In 2.1.1 Windows uses an internal linker for win32/64/ce which speeds the process up a bit. A Lazarus recompile then eats about 280MB.
+
    BaseClassA = class
 +
    // references ClassB
 +
    end;
 +
     
 +
    ClassB = class
 +
    // references BaseClassA
 +
    end;
 +
</syntaxhighlight>
 +
Discussion: https://forum.lazarus.freepascal.org/index.php/topic,25667.msg156115.html#msg156115
  
=== Do I need ppc386.cfg or fpc.cfg? ===
+
=== When I do ''var mytext: text;'' to declare a text file, I get "Unit1.pas(32,15) Error: Error in type definition". How can I fix this? ===
 +
The TControl class has a [[doc:lcl/controls/tcontrol.text.html|Text]] property. In a method of a form, that has higher visibility, the [[doc:rtl/system/text.html|Text]] type from the system unit. You can use the [[doc:rtl/system/textfile.html|TextFile]] type, which is just an alias for the Text type or you can add the unit to the type definition.
  
You only need fpc.cfg. This way the compiler knows where to find the libraries.
+
<syntaxhighlight lang="pascal">
 +
var
 +
  MyTextFile: TextFile;
 +
  MyText: System.Text;
 +
</syntaxhighlight>
  
=== How do I compile lazarus? ===
+
A similar name clash exists with assigning and closing a text file. TForm has a ''assign'' and a [[doc:lcl/forms/tcustomform.close.html|Close]] method. You can use [[doc:rtl/objpas/assignfile.html|AssignFile]] and [[doc:rtl/objpas/closefile.html|CloseFile]] or add the unit name ''System''.
  
Do something like this:
+
=== I get an error when using Printer.BeginDoc ===
$ cd lazarus
 
$ make clean all
 
  
=== How do I build other projects based upon the LCL ===
+
The unit Printers must be added to the uses section and the ''Printer4Lazarus'' package must be added to your project requirement in the IDE under: Project > Project Inspector > Add > New Requirement > Package Name.
  
If you can't use the IDE to build your applications, add the following lines to the end of your ''fpc.cfg''
+
If the Printer4Lazarus package is not in the list when opening the dropdown box it must be installed. The package is part of the Lazarus installation and can be found in: [lazarus installed directory][/|\]components[/|\]printers.
  
  # searchpath for other toolkits (Linux)
+
If you used the default installation directories [lazarus installed directory] is:
  -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/{YourToolKit}
 
  
  # searchpath for other toolkits (Windows)
+
{| class="wikitable"
  -Fu/{YourLazarusDirectory}/components/units/{YourToolKit}
+
! Operating system !! Lazarus installed directory
 +
|-
 +
| FreeBSD || /usr/local/share/lazarus
 +
|-
 +
| Linux || /usr/lib/lazarus
 +
|-
 +
| macOS || /Library/Lazarus/
 +
|-
 +
| Windows || c:\lazarus
 +
|}
  
:Where {YourToolKit} may be ''gtk2'', ''gnome'', ''qt'' or ''win32'' and run:
+
The same solution also applies to the exception you can get when referencing ''Printer.Printers''.
::ppc386 your.project.pp
 
  
'''Hint:''' Don't forget to install the development packages for your toolkit otherwise you might a recieve something like: [[Linker message: cannot find -l]].
+
=== When I try to compile a project, I get an error message "Cannot find Unit ..." ===
 +
Please see [[Unit not found - How to find units]]
  
=== What version of FPC is required? ===
+
For information on the error "Cannot find unit interfaces", see the next section.
  
FPC Version 2.0.4 has been released, and that is the recommended version. You can also use the svn version of fpc 2.0.5 and 2.1.x.
+
=== When I try to compile a project, I get an error message "Cannot find Unit interfaces" ===
 +
This error means that the compiler can not find the file 'interfaces.ppu' '''or''' the file was found, but it is wrong or outdated (the .ppu file date code is older than the date code of the compiler itself). Testing the compiler option settings can help debug these issues, via Project: Compiler Options... (use the Test button at the bottom of the dialog). This test also lets you check that the {TargetCPU} and {TargetOS} variables are set properly.
  
=== I can't compile Lazarus ===
+
The interfaces unit can be found in {LazarusDir}\lcl\units\{TargetCPU}-{TargetOS}\{LCLWidgetSet}\interfaces.ppu. For example: /home/username/lazarus/lcl/units/i386-linux/gtk/interfaces.ppu.
  
# Check if the compiler has the correct version
+
It is normal to have multiple versions of interfaces.ppu (in the proper directories) to allow compiling with different widgets.
# Check if the (fpc)libraries are from the same version.
 
# Check if you have a fpc.cfg and no old ppc386.cfg
 
# Check also the OS-dependent FAQs
 
  
=== When I try to compile a project, I have an error ===
+
If the interface.ppu file is in the folder matching the OS and CPU you selected in the project preferences, and you get this error, you are using a different compiler / RTL for compiling your project than you used for compiling your Lazarus IDE, or the libraries need to be recompiled to give the .ppu files newer compilation dates.  
==== "Cannot find Unit interfaces". How can I solve this?====
 
This compiled unit can be found in {LazarusDir}\lcl\units\{TargetCPU}-{TargetOS}\{LCLWidgetSet}\interfaces.ppu.  
 
  
Make sure, it is only there. If you have multiple versions of interfaces.ppu, then you have probably have a wrong configuration (for instance you added a lcl directory to a search path). Remove all interfaces.ppu, but the one in the directory above.
+
You can do one of the following:
 +
# Set the compiler in the Environment Options to the one you used to compile Lazarus. Also look carefully in the Environment Options to see if you are using the correct paths for the Lazarus directory and the FPC sources directory. Check that there is only one version of the compiler configuration file fpc.cfg - it should reside in /etc/ for Linux/Unix systems or in the same directory as the fpc compiler for Windows systems. Try to run "fpc -vt bogus" to check which fpc.cfg is being used in your system. Rogue copies often creep in if you have updated your compiler to a new version; they may be found in your home directory or in the same directory as the one in which you built your new compiler. DELETE THESE!
 +
# Rebuild the LCL (or Lazarus completely) with the compiler selected in the Environmnent Options. You can do this with Tools -> Build Lazarus. Before doing this, check the current settings in Tools -> Configure Build Lazarus.
 +
# You may also try to change the widgetset currently selected for the project. For example, the sample project "objectinspector" that comes with Lazarus is set to gtk by default. Compiling this project will surely give you "Can't find unit interfaces" in Windows platform. Changing widgetset to default(Win32) in [[IDE_Window:_Compiler_Options#Changing_the_LCLWidgetType_in_Version_1.1_and_above Project | Project Options | Compiler Options...]] should fix this issue.
  
If you selected a different widgetset than you used to build lazarus, you need to build the LCL for this widgetset.  
+
=== When I compile a project, that uses a LCL unit, I get a linker error ===
 +
Here is an example for such a linker error:
 +
/path/to/lazarus/lcl/units/x86_64-linux/wsimglist.o: In function `REGISTERCUSTOMIMAGELIST':
 +
/path/to/lazarus/lcl//widgetset/wsimglist.pp:266: undefined reference to `WSRegisterCustomImageList'
  
If it is there, but you get this error, you are using a different compiler / rtl for compiling your project than you used for compiling your Lazarus IDE. You can do one of the following
+
*Make sure yor project uses the package LCL. You can check this in the project inspector.
* Rebuild the LCL (or Lazarus completely) with the compiler selected in the Environmnent Options. You can this with Tools -> Build Lazarus. Before doing this, check the current settings in Tools -> Configure Build Lazarus.
+
*Make sure unit "interfaces" is used as one of the first units of your program.
* Change the compiler in the Environment Options to the one you used to compile Lazarus. Look carefully also in the Environment Options to see if you are using the correct paths for the Lazarus Directory and the FPC sources directory. Check that there is only one version of the compiler configuration file fpc.cfg - it should reside in /etc/ for Linux/Unix systems or in the same directory as the fpc compiler for Windows systems. Try to run "fpc -vt bogus" to check which fpc.cfg is being used in your system. Rogue copies often creep in if you have updated your compiler to a new version; they may be found in your home directory or in the same directory as the one in which you built your new compiler.  DELETE THESE!!
 
* You may also try to change the widgetset currently selected for the project. For example, the sample project "objectinspector" that comes with Lazarus is set to gtk by default. Compiling this project will surely give you "Can't find unit interfaces" in Windows platform. Changing widgetset to default(Win32) in Project | Compiler Options... | LCL Widget Type (various) should fix this issue.
 
  
=== When I try to compile delphi projects under lazarus, I have an error ===
+
{{Note|These functions are implemented by the LCL backends. By adding the unit interfaces, you link a LCL backend into your program.}}
==== at the line :{$R *.DFM} How can I solve this problem ? ====
 
  
Lazarus (or better Linux) doesn't know about resources, so you can't use them in the way Delphi/win32 does. However Lazarus uses a method pretty compatible with this. You can still use your Delphi layouts (.dfm files) if you use the following steps:
+
=== At the line :{$R *.DFM} How can I solve this problem (Lazarus with FPC < 2.4.0)? ===
 +
Lazarus (or better Linux) doesn't know about resources, so you can't use them in the way Delphi/Win32 does. However Lazarus uses a method pretty compatible with this. You can still use your Delphi layouts (.dfm files) if you use the following steps:
  
*You need a textual version of the .dfm files. D5 and higher are doing this as default. If you have older files: ALT-F12 to see the layout as text and paste/copy. When you have a text .dfm file, just copy it to a .lfm file.
+
*You need a textual version of the .dfm files. D5 and higher are doing this by default. If you have older files: {{keypress|Alt|F12}} to see the layout as text and paste/copy. When you have a text .dfm file, just copy it to a .lfm file.
 
*Create a file with lazres (in lazarus/tools) lazres yourform.lrs yourform.lfm
 
*Create a file with lazres (in lazarus/tools) lazres yourform.lrs yourform.lfm
 
*Add the following initialization section to
 
*Add the following initialization section to
  
      initialization
+
<syntaxhighlight lang="pascal">
      {$I yourform.lrs}
+
initialization
 +
{$I yourform.lrs}
 +
</syntaxhighlight>
  
Please keep in mind that not all properties in the dfm are supported yet by
+
Please keep in mind that not all properties in the dfm are supported yet by Lazarus, so you might get a crash.
lazarus, so you might get a crash.
 
  
==== 'Identifier not found LazarusResources'. ====
+
Edit: Since FPC 2.4.0, Delphi style resources are supported, so you don't need to change anything. Even Lazarus SVN already uses it as default projects. Note: it's still advised that you use Lazarus' Delphi project converter as there might still be unsupported properties.
  
 +
=== 'Identifier not found LazarusResources' ===
 
When creating a form Lazarus automaticaly add some extra units to the uses section of your form unit. During the conversion of a delphi unit to a Lazarus unit this does not happen. So you need to add LResources to the Uses section of your form unit.
 
When creating a form Lazarus automaticaly add some extra units to the uses section of your form unit. During the conversion of a delphi unit to a Lazarus unit this does not happen. So you need to add LResources to the Uses section of your form unit.
  
=== When accessing events of objects e.g. the onclick event of a button I get the following error. ERROR unit not found: stdCtrls ===
+
=== When accessing events of objects, ''e.g.'', the onclick event of a button, I get the following error. ERROR unit not found: stdCtrls ===
 
+
Make sure, in the Project -> Project Inspector, that your project depends on the package "LCL" and that you have installed the FPC sources.
Make sure, in the Project -> Project Inspector, that your project depends on the package 'LCL' and that you have installed the FPC sources.
 
  
 
Lazarus is the IDE and the visual components library LCL.
 
Lazarus is the IDE and the visual components library LCL.
Line 130: Line 275:
 
Environment -> Environment Options -> Files -> FPC source directory
 
Environment -> Environment Options -> Files -> FPC source directory
  
===How to embed a small file in the executable, without the need of a separate file? How to embed a resource?===
+
=== 'Fatal: Internal error XXXXYYZZW' ===
 +
An internal error is a compiler error that is not expected to happen (but is prepared to easily track down the problem if happens by giving code XXXXYYZZW). Every internal error is a bug, thus it's advised to report to the bugtracker (with small example that can demonstrate the internal error) when one gets it.
  
For example:
+
=== Fatal: Cannot find [...] used by [...], incompatible ppu=[filename], package [package name] ===
/your/lazarus/path/tools/lazres sound.lrs sound1.wav sound2.wav ...
 
will create sound.lrs from sound1.wav and sound2.wav.
 
  
Then include it *behind* the form lrs file:
+
When the compiler gives the message "Cannot find A used by B", Lazarus checks what pas/pp/ppu files are in the search path, and if there is a ppu file it inserts "incompatible ppu=filename, package".''
  
...
+
Explanation: FPC cannot use this ppu for one of these reasons:
initialization
 
{$i unit1.lrs} // this is main resource file (first)
 
{$i sound.lrs} // user defined resource file
 
 
   
 
   
end.
+
* it was compiled with another FPC version;
In your program you can then use:
+
* it was compiled with (depends on) some other ppu files that are not in the search path;
  Sound1AsString:=LazarusResources.Find('sound1').Value;
+
* you misconfigured some search path(s).
 +
 
 +
Without knowing how you installed FPC + Lazarus, I'd be tempted to delete both and start again (make sure to delete the fpc.cfg file).
 +
 
 +
=== Lazarus cannot open a project if last character of the path to it is a space ===
 +
 
 +
If you try to open a project like <tt>/home/bart/space /test.lpi</tt> (note the space just before /test.lpi), the Lazarus IDE will give an error saying it cannot find <tt>/home/bart/space /test.lpi</tt>.
 +
 
 +
This is a known limit of the IDE, which is caused by the fact that the IDE a.o. has to handle paths that users have supplied in edit controls, which have to be stripped from surrounding spaces. This limitation in no way affects user programs written in FPC/Lazarus. Avoid such pathnames for projects.
 +
 
 +
=== strToFloat - EConvertError: "0.nnn" is an invalid float ===
 +
 
 +
The "0.nnn" can be any floating point number. The problem is that your locale settings (eg DE Germany) are expecting a comma to be the decimal separator in numbers and not a decimal point. The solution is to add this to your code: <syntaxhighlight lang=pascal inline>DefaultFormatSettings.decimalSeparator := '.';
 +
</syntaxhighlight> to override your locale's decimal separator. Alternatively, instead of strToFloat and floatToStr, use the Pascal intrinsics val and str - they always need a decimal point.
 +
 
 +
== Debugger ==
 +
''See also [[GDB Debugger Tips]].''
 +
 
 +
=== How do I set up/configure for debugging ===
 +
[[Debugger_Setup |Setup the debugger]]
 +
 
 +
=== How can I inspect properties? ===
 +
You have to use FPC 2.4 or newer.
 +
 
 +
If you compile your application using -gw (dwarf debug info), you should be able to inspect properties.
 +
 
 +
{{Note|This is only true for properties that map directly to a variable (the "read" declaration points to a member, not a function).}}
 +
 
 +
If your property returns the value of a function it is very dangerous to evaluate/inspect it. It would require this function to be called, and very often it would change the values of some of your variables. This would mean it would alter the state of your application in the debugger, and any further code-execution, debugging or inspections would return incorrect results.
 +
 
 +
The optional ability to explicitly inspect the results of functions (with the risks described), and therefore calling code from the debugger is not yet implemented
 +
 
 +
=== Why does the debugger not show some Variables/Structures ("no such symbol"/"incomplete type") ===
 +
For problems debugging:
 +
* properties
 +
* Array of ... (Dynamic Array)
 +
* Variables in Nested Procedures
 +
* "no such symbol in context"
 +
* "incomplete type"
 +
 
 +
Please see [[GDB_Debugger_Tips]] and the and [[FpDebug#Properties]]
 +
 
 +
=== How can I debug FCL components from packages with Lazarus ===
 +
FCL components and classes are built without debug information by default and as a result, gdb cannot access component methods or properties. To build package components they must be rebuilt with a debug-line information "-gl" switch.
 +
 
 +
This example assumes you have a Linux distribution with /usr/local/ installation prefix and that the Database package fcl-db is what is needed to contain debug-line information.  While the fcl-db is used in this example, you may issue this make command from ANY of the included packages.
 +
 
 +
Before you begin, you need to locate your FPC path by examining your FPC configuration file.  The file (fpc.cfg) is located at /etc/fpc.cfg.  Display the contents of fpc.cfg and find your fpc installation path.  Look for a line starting with -Fu in the fpc.cfg:
 +
 
 +
-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/*
 +
 
 +
Make scripts are installing units into INSTALL_PATH/lib/fpc/$fpcversion/units/$fpctarget/,
 +
so you must be sure that /usr/local is the installation path, and should be assigned to INSTALL_PREFIX, otherwise the Make scripts will place units where they don't belong or the Make script will fail.
 +
 
 +
# Open a shell terminal
 +
# cd /user/local/share/src/fpc-2.3.1/fpc/fcl-db/
 +
# sudo make clean all install INSTALL_PREFIX=/usr/local OPT=-gl
 +
 
 +
{{Note|INSTALL_PREFIX parameter should be properly configured for units to be installed.}}
 +
In the sample below /usr/local is a default fpc path for Linux, but may vary on other OSes.
 +
 
 +
<syntaxhighlight lang="bash">make clean all install INSTALL_PREFIX=/usr/local OPT=-gl</syntaxhighlight>
 +
 
 +
Finally, after rebuilding any FCL units you may want to rebuild LCL as well.
  
=== How can I see debug output? ===
+
=== Problems with GDB on Mac ===
  
The LCL has in the LCLProc procedure to write debug output:
+
Lazarus has now support for lldb on Mac. See [[Installing_Lazarus_on_macOS#Step_5:_Configure_the_Debugger|Configuring the lldb debugger]].
* '''DebugLn:''' works about the same as WriteLn, but accepts only strings.
 
* '''DbgOut:''' works about the same as Write, but accepts only strings.
 
  
In normal circumstances the output is written to stdout. If stdout is closed, (for example when the application is {$AppType Gui} or compiled with -WG on windows), no output is written.
+
If you want to use gdb, you can find some info here: [[GDB_Debugger_Tips#macOS|GDB tips for Mac]]
  
Debug output can also be written to file. The LCLProc unit checks in its initialization the command line parameters for '--debug-log=<file>'. If it finds it sends debug output to <file>.
+
=== How can I use a log file for debugging? ===
 +
Lazarus provides a basic log framework (style [[DebugLn|<code>debugln(...)</code>]] ) in the unit [[LazLogger]]. See that page for more details.
  
If it doesn't find a --debug-log command line parameter, it looks if an environment variable xxx_debuglog exists, where xxx is the program file name without extension. For lazarus this would be lazarus_debuglog. If
+
=== How can I use a Log-file for debugging the IDE itself? ===
such an environment variable exists, it uses that as file to write debug output to. Example: if you do:
+
Lazarus itself uses [[LazLogger]].  
set lazarus_debuglog=c:\lazarus\debug.txt
 
debug output will be written to c:\lazarus\debug.txt.
 
  
Since this is implemented in lclproc, every application using lclproc, can use this output facility.
+
This means that you can run Lazarus with <syntaxhighlight lang="bash">--debug-log=lazarusdebuglog.txt</syntaxhighlight>
  
;Debuging Lazarus : Most usefull for windows: If you want output on a console, add {$APPTYPE console} to lazarus.pp ; Then rebuild Lazarus.
+
If this is not sufficient: in the IDE the extent of the information that is logged can be controlled with <code>--debug-enable</code>. See <code>--help</code> for a list of keywords, or install the package IdeLazLogger.
  
=== What is the meaning of the various file extensions used by Lazarus? ===
+
If you want output on a console (most useful for Windows), add the option '''-WC''' in the Tools / Configure "Build Lazarus" options. Then rebuild Lazarus.
 +
 
 +
See also [[Console Mode Pascal#Run in IDE with redirected output]]
  
The [[Lazarus Tutorial#The Lazarus files]] explains some extensions by an example.
+
== Contributing / Making Changes to Lazarus ==
Here is a brief list:
+
=== I created a Patch to dock the IDE Messages form on the "Source Code Editor" form (at bottom) ===
 +
Such patches will not be applied, because they only implement a small part of the needed docking. The goal is to create a complete dock manager and use that. A complete dock manager can dock all IDE windows and it allows to let the user define how to dock. For example dock the messages window above or below the source editor&#160;— or not at all. For instance,
  
; <code>*.lpi</code> : Lazarus Project Information file (stored in XML; contains project-specific settings)
+
+-------------------++--+
; <code>*.lpr</code> : Lazarus Program file; contains Pascal source of main program
+
|menu              ||  |
; <code>*.lfm</code> : Lazarus Form file; contains configuration information for all objects on a form (stored in a Lazarus-specific format; the actions are described by Pascal source code in a corresponding <code>*.pas</code> file)
+
+-------------------+|  |
; <code>*.pas</code> or <code>*.pp</code> : Unit with Pascal code (typically for a form stored in a corresponding <code>*.lfm</code> file)
+
+--++---------------+|  |
; <code>*.lrs</code> : Lazarus Resource file (this is a generated file; not to be confused with a Windows resource file).
+
|PI|| Source Editor ||CE|
: This file can be created with lazres tool (in directory Lazarus/Tools) using commandline: lazres myfile.lrs myfile.lfm
+
+--+|              ||  |
; <code>*.ppu</code> : Compiled unit
+
+--+|              ||  |
; <code>*.lpk</code> : Lazarus package information file. (stored in XML; contains package-specific settings)
+
|  |+---------------++--+
 +
|OI|+-------------------+
 +
|  ||messages          |
 +
+--++-------------------+
  
=== I have fixed/improved lazarus. How can I add my changes to the official lazarus source? ===
+
The dock manager can store the layout and restore it on next load. Preferably the dock manager can dock in pages too. The dock manager does not need to use drag and dropAll patches implementing docking without a dock manager makes it harder to implement a real dock manager and will be rejected.
Create a patch and send it to the developers. For details see [[Creating A Patch]].
 
=== When I do ''var mytext: text;'' to declare a text file, I get "Unit1.pas(32,15) Error: Error in type definition". How can I fix this?===
 
The TControl class has a [[doc:lcl/controls/tcontrol.text.html|Text]] property. In a method of a form, that has higher visibility, the [[doc:rtl/system/text.html|Text]] type from the system unit. You can use the [[doc:rtl/system/textfile.html|TextFile]] type, which is just an alias for the Text type or you can add the unit to the type definition.
 
  var
 
  MyTextFile: TextFile;
 
  MyText: System.Text;
 
A similar name clash exists with assigning and closing a text file. TForm has a ''assign'' and a [[doc:lcl/forms/tcustomform.close.html|Close]] method. You can use [[doc:rtl/objpas/assignfile.html|AssignFile]] and [[doc:rtl/objpas/closefile.html|CloseFile]] or add the unit name ''System''.
 
  
=== I get an error when using Printer.BeginDoc ===
+
An example for such a dock manager is the package [[anchordockdsgn]]
  
The unit Printers must be added to the uses section.
+
=== I have fixed/improved Lazarus. How can I add my changes to the official Lazarus source? ===
 +
Create a patch and send it to the developers. For details, see [[Creating A Patch]].
  
The Printer4Lazarus package must be added to your project requirement in the IDE under:
+
=== How can I install more than one copy of Lazarus? ===
Project|Project Inspector|Add|New Requirement|Package Name:
 
  
If the package Printer4Lazarus package is not in the list when opening the dropdown box it must be installed. The package is part of the Lazarus installation and can be found in:
+
Please see [[Multiple Lazarus]]
[lazarus installed directory]\components\printers
 
  
If you used the default installation directories [lazarus installed directory] is:
+
=== How can I become a Lazarus developer and access management in the SVN and bug-tracker? ===
*Windows: c:\lazarus 
+
First of all, you must learn about Lazarus, to prove your knowledge and skill.  Start by reading the [[Lazarus Documentation]] wiki article, read the Lazarus source code, giving a look at the {{gitlab|issues|Lazarus||Lazarus Bug-Tracker}}, fix some bugs, and if you think you are ready, contact the developers on the [https://www.mail-archive.com/lazarus@miraclec.com/ mailing list].
*Linux: /usr/lib/lazarus
 
  
 
== Where is ... defined ==
 
== Where is ... defined ==
 
 
=== Virtual key constants ===
 
=== Virtual key constants ===
Virtual key constants are defined in LCLType. Add LCLtype to your <b>uses</b>.
+
Virtual key constants are defined in [[doc:lcl/lcltype|LCLType]]. Add LCLtype to your <b>uses</b>.
  
 
== Using the IDE ==
 
== Using the IDE ==
  
 
=== How can I use "identifier completion"? ===
 
=== How can I use "identifier completion"? ===
 +
 
You can invoke identifier completion by pressing [ctrl][space].
 
You can invoke identifier completion by pressing [ctrl][space].
 
Under the menu item ''Environment -> Editor Options -> Code Tools -> Automatic Features'' you can set how quick this should happen automatically.
 
Under the menu item ''Environment -> Editor Options -> Code Tools -> Automatic Features'' you can set how quick this should happen automatically.
 +
 +
=== Can I change the code editor font and colours? ===
 +
 +
Yes, see the menu item ''Tools -> Options'' and use the Editor/Display and Colors sections. On Windows you may find that the default Courier (and some other typefaces) are either too sharp or too soft, either selecting/deselecting 'Disable anti-aliasing'. TrueType fonts are an improvement, such as the free "Bitstream Vera Sans Mono" font available from [https://download.gnome.org/sources/ttf-bitstream-vera/1.10/]. (To install a new font, unzip and copy the files into a suitable folder. In Windows XP you will need to use the Fonts section of the Control Panel. In Windows 7 you may select all the font files, right-click and find an Install option in the pop-up menu)
 +
 +
=== How can I disable specific compiler warning messages? ===
 +
 +
To disable specific compiler warning messages you can either insert a '''{$WARN number OFF}'''  directive in your code or use FPC's option '''-vm<x>'''. You can find details for these in FPC's [https://www.freepascal.org/docs.html Programmer's guide] and Appendix A of the [https://www.freepascal.org/docs.html User's guide].
 +
 +
=== What are the IDE command line options? ===
 +
 +
See [[Lazarus command line options]].
  
 
== Linux ==
 
== Linux ==
 +
=== Typing in edit fields generate duplicate letters ===
 +
 +
This is more likely to happen under Ubuntu and Ubunto derived distros, and with GNOME Desktop but other distros/Desktop environments can be affected too.
 +
 +
The problem is originated by bugs in the ibus Input Method System. Unfortunately Ibus is the default input method of GNOME desktop.
 +
 +
If you don't know what an IM is, this means that you do not need it, and therefore the easiest way is to disable IM's at all.
 +
 +
In order to do that you have a number of options, namely:
 +
 +
* 1 - Disable (or set to "none") the Input Method in System Settings->Preferences->Input Method
 +
 +
* 2 - Add the three following lines in /etc/profile (system wide)
 +
export GTK_IM_MODULE=gtk-im-context-simple
 +
export QT_IM_MODULE=simple
 +
export XMODIFIERS=@im=none
 +
* 3 - Add a file named ''input_method.sh'' containing just the 3 lines above in /etc/profile.d (system wide)
 +
 +
* 4 - Add the 3 lines above in the home directory ~/.xprofile (per user). If there's no ~/.xprofile in your home directory, you should create one.
 +
 +
* 5 - Create a Lazarus launching script containing the same 3 lines. (affects only Lazarus)
 +
 +
Methods 1 and 2 may not survive after a system update, while 3,4 and 5 will.
 +
 +
Be aware that both GTK and QT applications may change dynamically the IM. If you experience the problem in an apparently random way, chances are good that some other application
 +
is enabling again an IM and fails to set to default when terminates. If such is the case method 5 is the only one suitable.
 +
 +
You may find more information about Input Methods, and how to deal with them in:
 +
 +
https://fedoraproject.org/wiki/I18N/InputMethods (This is Fedora specific but most informations apply in general)
 +
 +
http://www.pinyinjoe.com/linux/ubuntu-12-chinese-setup.htm (This is Ubuntu specific, but again most informations apply in general. It explains how to '''enable''' IM but the info can be used also to '''disable''' it)
  
 
=== How can I debug on Linux without the IDE? ===
 
=== How can I debug on Linux without the IDE? ===
 
 
First of all you need a debugger. gdb is the standard debugger under linux and
 
First of all you need a debugger. gdb is the standard debugger under linux and
 
there are several GUI-frontends available. One common frontend is ddd, which is
 
there are several GUI-frontends available. One common frontend is ddd, which is
Line 223: Line 464:
 
you should then use the following commands to start a debug session:
 
you should then use the following commands to start a debug session:
  
  $ make clean; make OPT=-dDEBUG
+
<syntaxhighlight lang="bash">
  $ ddd lazarus
+
make clean; make OPT=-dDEBUG
 +
ddd lazarus
 +
</syntaxhighlight>
  
Be warned however, that ddd is not as comfortable as e.g. the Lazarus debugger.
+
Be warned, however, that ddd is not as comfortable as, ''e.g.'', the Lazarus debugger, especially if it comes to view the contents of a variable you have to take into account that ddd/gdb are case sensitive whereas Pascal is case-insensitive. Therefore, you have to type all variable names in uppercase to see their contents. For more information see the fpc-manuals.
Specially if it comes to view the contents of a variable you have to take into
 
account that ddd/gdb are case sensitive whereas Pascal is case-insensitive.
 
Therefore you have to type all variable names in uppercase to see their
 
contents. For more information take a look into the fpc-manuals.
 
 
 
=== I can debug now but ddd does not find my sources or complains that they contain no code. Whats that? ===
 
 
 
This is a path-related problem with either gdb or ddd. You can aviod this by
 
  
 +
=== I can debug now but ddd does not find my sources or complains that they contain no code. What's that? ===
 +
This is a path-related problem with either gdb or ddd. You can avoid this by
 
* Use the "Change directory" command from the ddd menu and choose the directory where the sources are located. The drawback of this method is that you now can't use the source of the program you started with (e.g. lazarus). Thus it may be neccessary to change the directory multiple times.
 
* Use the "Change directory" command from the ddd menu and choose the directory where the sources are located. The drawback of this method is that you now can't use the source of the program you started with (e.g. lazarus). Thus it may be neccessary to change the directory multiple times.
 
* In ddd goto [Edit] [gdb-settings] and set the search-path
 
* In ddd goto [Edit] [gdb-settings] and set the search-path
Line 243: Line 480:
 
       directory /your/path/to/lazarus/lcl/include
 
       directory /your/path/to/lazarus/lcl/include
  
=== I receive an error during the linking that states /usr/bin/ld can't find -l<some lib> ===
+
=== I receive an error during the linking that states /usr/bin/ld: cannot find -l&lt;some lib&gt; ===
 +
For example:
 +
  /usr/bin/ld: cannot find -lgdk
 +
 
 +
This means an external library was not found. In the above case under Linux it means the libgdk.so or libgdk.a was not found. Normally this means, you forgot to install the development package of this library. In the case of gdk the package is called under the Fedora Core distribution: 'gtk+-devel-1.2.10-33'.
  
 
; '''Package Based Distributions''' : You need to install the package that provides the lib<somelib>.so or lib<somelib>.a files. Dynamic libs under linux have the extension .so, while static libs have the extension .a. On some Linux distro's you have installed the package (rpm, deb) <packagename> which provides <some lib>, but you also need the development package (rpm, deb), normally called <packagename>-dev, which contains the .a (static lib) and/or the .so (dynamic lib).
 
; '''Package Based Distributions''' : You need to install the package that provides the lib<somelib>.so or lib<somelib>.a files. Dynamic libs under linux have the extension .so, while static libs have the extension .a. On some Linux distro's you have installed the package (rpm, deb) <packagename> which provides <some lib>, but you also need the development package (rpm, deb), normally called <packagename>-dev, which contains the .a (static lib) and/or the .so (dynamic lib).
 +
 +
: Some distributions have commands to find which package contains a file:
 +
: '''Mandriva'''
 +
 +
<syntaxhighlight lang="bash">
 +
urpmf lib<somelib>.so
 +
</syntaxhighlight>
 +
 +
:will list all packages containing the file named lib<somelib>.so, you'll have to install those ending in -devel
 +
 +
: '''Debian'''
 +
 +
:install the apt-file utility (apt-get install apt-file) then
 +
 +
<syntaxhighlight lang="bash">
 +
apt-file search lib<somelib>.so
 +
</syntaxhighlight>
 +
 +
:will list all packages containing the file named lib<somelib>.so, you'll have to install those ending in -dev
 +
 +
: '''SuSE'''
 +
 +
:SuSE installs the gtk devel libs under /opt/gnome/lib (or /opt/gnome/lib64 for 64 bits), which is not in the standard lib path. Simply add it to your /etc/fpc.cfg. (-Fl/opt/gnome/lib).
  
 
; '''Source Based Distributions and Manual Compilation (LFS)''' : Make sure that there is a lib<somelib>.a in the path, and that it contains the right version. To let the linker find the dynamic library, create a symlink called lib<some lib>.so to lib<some lib><version>-x,y.so if necessary (and/or for static lib; lib<some lib>.a to lib<some lib><version>-x,y.a).
 
; '''Source Based Distributions and Manual Compilation (LFS)''' : Make sure that there is a lib<somelib>.a in the path, and that it contains the right version. To let the linker find the dynamic library, create a symlink called lib<some lib>.so to lib<some lib><version>-x,y.so if necessary (and/or for static lib; lib<some lib>.a to lib<some lib><version>-x,y.a).
  
; '''FreeBSD''' : As source based distro's, and also make sure you have -Fl/usr/local/lib in your fpc.cfg and/or Lazarus library path. Keep in mind that GTK1.2 has "gtk12" as package name under FreeBSD. (same for glib) NOTE: This has changed as of late. Newest ports have gtk-12 and glib-12 as well. You might stumble on this problem, since FPC requires the "-less" ones, you will need to symlink them like this:
+
: '''FreeBSD''' : As source based distro's, and also make sure you have -Fl/usr/local/lib in your fpc.cfg and/or Lazarus library path. Keep in mind that GTK1.2 has "gtk12" as package name under FreeBSD. (same for glib) NOTE: This has changed as of late. Newest ports have gtk-12 and glib-12 as well. You might stumble on this problem, since FPC requires the "-less" ones, you will need to symlink them like this:
 +
<syntaxhighlight lang="bash">
 +
# as root
 +
cd /usr/local/lib && ln -s libglib-12.so libglib12.so
 +
cd /usr/X11R6/lib && ln -s libgtk-12.so libgtk12.so
 +
cd /usr/X11R6/lib && ln -s libgdk-12.so libgdk12.so
 +
</syntaxhighlight>
 +
 
 +
: '''NetBSD''' : As source based distro's, and also make sure you have -Fl/usr/pkg/lib in your fpc.cfg and/or Lazarus library path
  
[]# cd /usr/local/lib && ln -s libglib-12.so libglib12.so
+
: '''Fedora''' : In the "add/remove software" panel search for: "gtk2-devel", "glibc-devel" ([https://www.mail-archive.com/lazarus@lists.lazarus.freepascal.org/msg03637.html see here]), "libx11-devel"
[]# cd /usr/X11R6/lib && ln -s libgtk-12.so libgtk12.so
 
[]# cd /usr/X11R6/lib && ln -s libgdk-12.so libgdk12.so
 
  
; '''NetBSD''' : As source based distro's, and also make sure you have -Fl/usr/pkg/lib in your fpc.cfg and/or Lazarus library path
+
=== I receive a warning during the linking that states: Warning: "crtbeginS.o" (or "crtendS.o") not found ===
 +
The actual filename may also be "crtbegin.o" or "crtend.o"<br>
 +
In most cases linking will not fail.<br>
 +
Here's how to find where that file is (you need to have gcc installed, and gcc needs to target the same architecture as fpc), and tell the fpc (which tells the linker):
 +
<syntaxhighlight lang="bash">
 +
bart@simenon ~ $ gcc --print-file-name crtbeginS.o
 +
/usr/lib/gcc/x86_64-linux-gnu/5/crtbeginS.o
 +
</syntaxhighlight>
  
=== How can I convert a kylix 2 project into a lazarus project? ===
+
Add the path into fpc.cfg:
 +
# path to the gcclib
 +
#ifdef cpui386
 +
#-Fl/usr/lib/gcc/x86_64-linux-gnu/5  if you have a 32-bit fpc: fill in the correct path here
 +
#endif
 +
#ifdef cpux86_64
 +
-Fl/usr/lib/gcc/x86_64-linux-gnu/5
 +
#endif
 +
Note: On Linux the default (external) linker is ld. This is part of the linux distribution and not part of, or built with, FreePascal.
  
 +
=== How can I convert a Kylix 2 project into a Lazarus project? ===
 
Nearly the same way as converting a Kylix project into a Delphi/VCL project.
 
Nearly the same way as converting a Kylix project into a Delphi/VCL project.
  
The LCL (Lazarus Component Library) tries to be compatible to Delphis VCL.
+
The LCL (Lazarus Component Library) tries to be compatible to Delphi's VCL.
Kylix CLX tries to be QT compatible.
+
Kylix's CLX tries to be QT compatible. Here are some general hints:
Here are some general hints:
 
  
 
* Rename all used CLX Q-units like QForms, QControls, QGraphics, ... into their VCL counterparts: Forms, Controls, Graphics, ...
 
* Rename all used CLX Q-units like QForms, QControls, QGraphics, ... into their VCL counterparts: Forms, Controls, Graphics, ...
Line 273: Line 558:
 
* Remove {$R *.xfm} directive
 
* Remove {$R *.xfm} directive
 
* Add {$mode objfpc}{$H+} or {$mode delphi}{$H+} directive to .pas and .lpr files
 
* Add {$mode objfpc}{$H+} or {$mode delphi}{$H+} directive to .pas and .lpr files
* Add an initialization section to the end of each form source and add an include directive for the .lrs file (lazarus resource file):
+
* Add an initialization section to the end of each form source and add an include directive for the .lrs file (Lazarus resource file):
  initialization
+
<syntaxhighlight lang="pascal">
    {$I unit1.lrs}
+
initialization
 +
{$I unit1.lrs}
 +
</syntaxhighlight>
 +
 
 
:The .lrs files can be created via the lazres tool in: (lazarusdir)/tools/lazres.
 
:The .lrs files can be created via the lazres tool in: (lazarusdir)/tools/lazres.
 
:For example: ./lazres unit1.lrs unit1.lfm
 
:For example: ./lazres unit1.lrs unit1.lfm
  
 
* Fix the differences. The LCL does not yet support every property of the VCL and the CLX is not fully VCL compatible.
 
* Fix the differences. The LCL does not yet support every property of the VCL and the CLX is not fully VCL compatible.
 +
 +
* To make it more platform independent, reduce unit libc (which is deprecated) references and substitute with native FPC units like baseunix/unix as much as possible. This will be necessary to support other targets than linux/x86 (including macOS, FreeBSD and Linux/x86_64)
  
 
=== When compiling lazarus the compiler can not find a unit. e.g.: gtkint.pp(17,16) Fatal: Can't find unit GLIB ===
 
=== When compiling lazarus the compiler can not find a unit. e.g.: gtkint.pp(17,16) Fatal: Can't find unit GLIB ===
 
 
1. Check a clean rebuild: do a 'make clean all'
 
1. Check a clean rebuild: do a 'make clean all'
  
Line 314: Line 603:
 
''#'' cd /usr/lib/fpc/''version''/
 
''#'' cd /usr/lib/fpc/''version''/
  
''#'' ./samplecfg /usr/lib/fpc/''version'' /etc
+
''#'' sudo ./samplecfg /usr/lib/fpc/''\$version'' /etc
 
 
Note! Do not put - / - after etc because if you do that the system will create a file - /etc/fpc.cfg/fpc.cfg. In fact we want that samplecfg make a file - /etc/fpc.cfg - not the folder /etc/fpc.cfg.
 
  
=== I have installed the binary version, but when compiling a simple project, lazarus gives: Fatal: Can't find unit CONTROLS ===
+
{{Note|Do not a slash ("/") after etc, because if you do, the system will create a folder <code>/etc/fpc.cfg/fpc.cfg</code>. In fact, we want samplecfg to make a file <code>/etc/fpc.cfg</code>, not the folder <code>/etc/fpc.cfg</code>.}}
  
 +
=== I have installed the binary version, but when compiling a simple project, Lazarus gives: Fatal: Can't find unit CONTROLS ===
 
Probably you are using a newer fpc package, than that used for building the
 
Probably you are using a newer fpc package, than that used for building the
 
lazarus binaries. The best solution is to download the sources and compile
 
lazarus binaries. The best solution is to download the sources and compile
Line 325: Line 613:
 
via svn:
 
via svn:
  
  $ bash
+
<syntaxhighlight lang="bash">bash
  $ svn checkout http://svn.freepascal.org/svn/lazarus/trunk lazarus
+
svn checkout http://svn.freepascal.org/svn/lazarus/trunk lazarus
  $ cd lazarus
+
cd lazarus
  $ make clean all
+
make clean all</syntaxhighlight>
  
Make sure that lazarus get the new source directory:
+
Make sure that Lazarus get the new source directory:
 
Environment->General Options->Files->Lazarus Directory Top
 
Environment->General Options->Files->Lazarus Directory Top
  
===Lazarus compiles, but linking fails with: libgdk-pixbuf not found===
+
=== Lazarus compiles, but linking fails with: libgdk-pixbuf not found ===
Either install the gdk-pixbuf library for gtk1.x or disable the use:
+
Install the gdk-pixbuf library for gtk1.x:
  
 
Where to find the gdk-pixbuf library:
 
Where to find the gdk-pixbuf library:
  
 
RPMs:
 
RPMs:
http://rpmfind.net/linux/rpm2html/search.php?query=gdk-pixbuf&submit=Search+...&system=&arch=
+
https://rpmfind.net/linux/rpm2html/search.php?query=gdk-pixbuf&submit=Search+...&system=&arch=
  
 
Debian packages:
 
Debian packages:
Line 347: Line 635:
 
ftp://ftp.gnome.org/pub/gnome/unstable/sources/gdk-pixbuf/
 
ftp://ftp.gnome.org/pub/gnome/unstable/sources/gdk-pixbuf/
  
 +
'''Ubuntu 8.10:'''
 +
 +
If you are compiling Lazarus with GTK 2.0 you'll get a "libgdk-pixbuf2.0" not found error. Just install libgtk2.0-dev using apt on
 +
this way:
  
How to disable the use in lazarus: In Tools->Configure "Build Lazarus" add the option
+
<syntaxhighlight lang="bash">apt-get install libgtk2.0-dev</syntaxhighlight>
'-dNoGdkPixBufLib'
 
or at command line:
 
"make clean all OPT=-dNoGdkPixBufLib".
 
  
===I have SuSE and I get /usr/bin/ld: cannot find -lgtk Error: Error while linking===
+
=== I have SuSE and I get /usr/bin/ld: cannot find -lgtk Error: Error while linking ===
SuSE installs the gtk devel libs under /opt/gnome/lib (or /opt/gnome/lib64 for 64 bits), which is not in
+
Older SuSE versions (before SuSE 11) install the gtk devel libs under /opt/gnome/lib (or /opt/gnome/lib64 for 64 bits), which is not in the standard lib path. Simply add it to your /etc/fpc.cfg (-Fl/opt/gnome/lib).
the standard lib path. Simply add it to your /etc/fpc.cfg.
 
(-Fl/opt/gnome/lib).
 
  
===Lazarus crashes with runtime error 211 after I installed a component===
+
=== I have Kubuntu and I get /usr/bin/ld: cannot find -lgtk-x11-2.0===
 +
 
 +
You can either use the QT or the GTK2 backend. Default is GTK2. For GTK2 install the kubuntu package ''libgtk2.0-dev''.
 +
 
 +
=== Lazarus crashes with runtime error 211 after I installed a component ===
 
After I installed a component, Lazarus crashes with the following message:
 
After I installed a component, Lazarus crashes with the following message:
 
  Threading has been used before cthreads was initialized.
 
  Threading has been used before cthreads was initialized.
Line 365: Line 656:
 
How can I fix this?
 
How can I fix this?
  
Your freshly installed component is using threads. Fpc on *nix doesn't automatically include threading support, but it must be intialized. This initialization is done in the cthreads unit. Every application using the component needs to add this unit to the uses clause of the main program. Lazarus itself is no exception. This can be done in two ways:
+
Your freshly installed component is using threads. FPC on *nix doesn't automatically include threading support, but it must be intialized. This initialization is done in the cthreads unit. Every application using the component needs to add this unit to the uses clause of the main program. Lazarus itself is no exception. This can be done in two ways:
  
1) Change the source of ide/lazarus.pp: add the cthreads as first unit to the uses clause, so that is looks like this:
+
1) Open the package. In the package editor click on ''Options''. Under page ''Usage'' add to the ''custom'' options '''-dUseCThreads'''. Then rebuild the IDE. This way the cthreads unit will be automatically used by the IDE under unix and the cthreads are initialized.
uses
 
  //cmem,
 
  cthreads,
 
  {$IFDEF IDE_MEM_CHECK}
 
...
 
and rebuild lazarus.
 
  
2) In order to avoid modifying lazarus.pp file, a fpc compiler option could be used. Once package that uses threads has been compiled, open menu Tools->Configure "build Lazarus". Configure "build Lazarus" dialog will be shown, in field "Options:" type -Facthreads and then press "OK" button. The next step is to install the package. Lazarus will be built with option -Facthreads which means that it will treat main program as if unit cthreads where first in uses clause.  
+
2) In order to avoid modifying package, an FPC compiler option could be used directly. Open menu Tools->Configure "build Lazarus". "Configure build Lazarus" dialog will be shown; in field "Options:" type <code>-Facthreads</code> and then press "OK" button. The next step is to install the package. Lazarus will be built with option -Facthreads which means that it will treat main program as if unit cthreads where first in uses clause.
  
''Hint:'' Maybe your old (non-crashing) lazarus executable is stored as lazarus.old in the same directory as the crashing lazarus executable.
+
''Hint:'' Maybe your old (non-crashing) Lazarus executable is stored as lazarus.old in the same directory as the crashing Lazarus executable.
  
===When I run a program with threads I get runtime error 232===
+
See also [[Multithreaded Application Tutorial#Units needed for a multithreaded application]]
 +
 
 +
=== When I run a program with threads I get runtime error 232 ===
 
The complete error message is:
 
The complete error message is:
 
  This binary has no thread support compiled in.
 
  This binary has no thread support compiled in.
Line 387: Line 674:
 
'''Solution''': Add cthreads as first unit to the uses clause of your main program, usually the .lpr-file.
 
'''Solution''': Add cthreads as first unit to the uses clause of your main program, usually the .lpr-file.
  
===I have Ubuntu Breezy and my fonts in Lazarus IDE look too big===
+
=== I have Ubuntu Breezy/Mandriva KDE3 and my fonts in Lazarus IDE look too big ===
 
If Lazarus is compiled with Gtk1.2, the settings in Gnome Preferences/Font don't have any effect as
 
If Lazarus is compiled with Gtk1.2, the settings in Gnome Preferences/Font don't have any effect as
 
they are related to Gtk2.
 
they are related to Gtk2.
Line 394: Line 681:
 
these lines to it:
 
these lines to it:
  
<pre>
+
style "default-text" {
style "default-text" {
+
        fontset = "-*-arial-medium-r-normal--*-100-*-*-*-*-iso8859-1,\
      fontset = "-*-arial-medium-r-normal--*-100-*-*-*-*-iso8859-1,\
+
                  -*-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
                  -*-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
+
}
}
+
 
+
class "GtkWidget" style "default-text"
class "GtkWidget" style "default-text"
 
</pre>
 
  
===How can my gtk programs use custom rc files?===
+
If this is not enough try and create also a .gtkrc symlink to .gtkrc.mine . It worked in this way under Xubuntu 7.10, Mandriva 2009.0 KDE3.
  
 +
=== How can my gtk programs use custom rc files? ===
 
Option a)
 
Option a)
 
Name the rc file ''yourprogram.gtkrc'' and put it in the same directory where the executable is.
 
Name the rc file ''yourprogram.gtkrc'' and put it in the same directory where the executable is.
Line 412: Line 698:
 
Best done before ''Application.Initialize'' in the .lpr file with ''{$IFDEF LCLGtk}''.
 
Best done before ''Application.Initialize'' in the .lpr file with ''{$IFDEF LCLGtk}''.
  
===I have Ubuntu and I cannot compile for Gtk2 due to missing libraries===
+
Option c)
 +
Use unit ''gtk2'' and call ''gtk_rc_parse('your_rc_file'));'' and ''gtk_rc_reparse_all;''.
 +
 
 +
=== I have Ubuntu and I cannot compile for Gtk2 due to missing libraries ===
 
Ubuntu has a problem with not creating all the symbolic links that you'll need even when the libraries are installed.  Make sure that all missing libraries when trying to link for Gtk2 have their appropriate links.  For instance, you might need to do:
 
Ubuntu has a problem with not creating all the symbolic links that you'll need even when the libraries are installed.  Make sure that all missing libraries when trying to link for Gtk2 have their appropriate links.  For instance, you might need to do:
  
<pre>
+
<syntaxhighlight lang="bash">
 
cd /usr/lib
 
cd /usr/lib
 
sudo ln -s libgdk-x11-2.0.so.0 libgtk-x11-2.0.so
 
sudo ln -s libgdk-x11-2.0.so.0 libgtk-x11-2.0.so
</pre>
+
</syntaxhighlight>
  
 
Make sure that the [whatever].so symbolic links are created and point to the actual libraries.
 
Make sure that the [whatever].so symbolic links are created and point to the actual libraries.
  
===How can I compile a program for Gtk2?===
+
=== Lazarus runs differently with Linux vs. Windows.  What do I need to know? ===
  
At the moment, the Gtk2 compiled IDE is a little unstable, but you can compile software for Gtk2 using the Gtk1 IDE.
+
If you use readln(); and writeln(); for your input and output the console window (sometimes called terminal window) is not going to pop up as it does with Windows.  You will need to access this window with View - Debug Windows - Terminal Output.  Unlike with Windows you can not use backspace to correct typing errors.  The 'Enter' key on the numeric keypad may not work either, depending on the widgetset the IDE was built for. Type carefully!
  
To start with recompile LCL for Gtk2. Go to the menu "Tools"->"Configure Build Lazarus" and set LCL to clean+build and everything else to none.
+
Because Linux is case sensitive you will need to take care that you pay attention to case when referencing or accessing files.
  
Now click Ok and go to the menu "Tools"->"Build Lazarus"
+
== Windows ==
 +
=== When I cycle/rebuild the compiler, I get ===
 +
==== The name specified is not recognized as an internal or external command, operable program or batch file.>& was unexpected at this time ====
 +
In the compiler directory there is an OS2 scriptfile named make.cmd. Different versions of Windows also see this as a script file, so remove it since what is needed for OS2 becomes a hindrance on Windows.
  
Now you can compile your software with Gtk2 going on the Compiler options and changing the widgetset to Gtk2.
+
==== make[3]: ./ppc1.exe: Command not found ====
 +
Somehow make has lost its path (reason unknown). Try to cycle with a basedir set like:
 +
<syntaxhighlight lang="dos">
 +
make cycle BASEDIR=your_fpc_source_dir_herecompiler
 +
</syntaxhighlight>
  
===I get this message: "[WARNING] ** Multibyte character encodings (like UTF8) are not supported at the moment."===
+
=== When I try to make Lazarus I get: ===
 +
==== make.exe: * * * interfaces: No such file or directory (ENOENT). Stop.make.exe: * * * [interfaces_all] Error 2 ====
 +
You need to upgrade your make.
  
Since revision 10535 (0.9.21) this message doesn't exist anymore.  
+
==== makefile:27: *** You need the GNU utils package to use this Makefile. Stop. ====
Previously it was used to warn that a UTF-8 encoding was used. The internal keyhandling routines for the gtk1 widgetset couldn't handle such encoding for keypresses, with the result that keypresses with for instance accented chars were not or wrong detected.
+
Make sure you didn't install FPC in a path with spaces in the name. The
 +
Makefile doesn't support it.
 +
 
 +
=== How can I give my program an XP look like Lazarus has? ===
 +
Project -> Project Options -> Check 'Use manifest to enables themes'.
 +
 
 +
=== When I run Windows program created in Lazarus it starts with a DOS window ===
 +
Specify the -WG argument (Windows GUI) on the command line of the compiler or in the Lazarus IDE check the Windows GUI check box on the compiler options dialog box (Project menu -> Compiler Options -> Config and Target -> target OS Specific options.
 +
 
 +
== macOS ==
 +
 
 +
=== Why does compiling a project fail with 'unknown section attribute: no_dead_strip'? ===
 +
Dead code stripping is not supported by the assembler and linker before Xcode 1.5 (available for macOS 10.3.9). Disable the compiler options:
 +
 
 +
*Code > Unit style > Smart linkable (-CX)
 +
*and Linking > Link Style > Link smart (-XX)
  
(original text for older versions of lazarus)<br>
+
=== Xcode 3.1 and later ===
<strike>
+
The macOS linker in Xcode 3.1 (2007, Leopard 10.5) and later does not support stripping the symbol table attached to the output of the assembler and link editor. The linker supported stripping, for 32 bit executables only, up to Xcode 2.5 (2005, Tiger 10.4).
This warning message indicates that your locale enconding is set to utf-8. If you are using Gtk 1 this can be a serious problem and prevent the correct working of Lazarus or software created with Lazarus.
 
  
To work around this, just change your locale to a non utf-8 before executing the program on the command line, like this:
+
You will need to manually run the strip command line utility instead after compiling your executable.
  
<pre>
+
=== Debugging ===
export LC_CTYPE="pt_BR"
+
[[GDB_Debugger_Tips#Mac_OSX|Please see here for debugger issues under macOS]]
export LANG="pt_BR"
 
export LANGUAGE="pt_BR"
 
./lazarus
 
</pre>
 
  
Substitute pt_BR with the locale for your country. You can create a script to automate this.
+
== Licensing ==
</strike>
+
=== Can I make commercial applications with Lazarus? ===
 +
Yes, the LCL is licensed under the [[FPC modified LGPL|LGPL with an exception]], which allows you to link to it statically without releasing the source of your application. Modifications and enhancements to the LCL must be distributed with source. Lazarus, the IDE, is licensed under the GPL.
 +
The LCL consists only of the code in the directory named "lcl", other code may not be covered by this statement.
  
== Windows ==
+
=== Why are some components restricted from usage in commercial application? ===
 +
Lazarus comes with additional components, that were developed by third parties. Those are under various other Licenses. If you wish to use them you need to see the License within the source files of those packages.
 +
Most of those 3rd party components are in the directory "components".
 +
 
 +
=== How do I know if a Component is part of the LCL? ===
 +
All LCL units are in the directory "lcl". A list of units belonging to the LCL can be found  [https://lazarus-ccr.sourceforge.io/docs/lcl/ here]. If your code uses units not listed on this page, you may have used a component that is not part of the LCL.
 +
 
 +
=== Can I make commercial plug-ins for Lazarus? ===
 +
Yes, the IDEIntf part of the IDE is licensed under the LGPL with the same exception, so that shared data structures in this part will not force you to license your plug-in or design-time package under the GPL. You are free to choose a plug-in of any license; we don't want to limit your choice. Therefore non-GPL compatible plug-ins are allowed. Note that it's not allowed to distribute a precompiled Lazarus with these non-GPL-compatible plugins included statically; however, we do not see this as a severe limitation, since recompiling Lazarus is easy.
 +
 
 +
== Using the Forum ==
 +
=== What is the correct way to ask questions in the forum? ===
 +
First and most important: '''always mention which Lazarus version, Free Pascal version, Widgetset, CPU Architecture and Operating System (with full version) that you are using!''' Don't just say that you are using "the latest version"; please state the exact version number. For snapshots, the revision number and/or date are also important.
 +
 
 +
When asking a programming question, '''always try to include some source code which demonstrates the problem'''. Please surround your code with [code=pascal]...[/code] tags (or use the Insert code button in the forum post editor toolbar). You can attach complete programs as zip files if you want. Use Lazarus/Project/Publish Project to help with that.
 +
 
 +
If you get an error on your code, '''always specify what the error is'''. Simply copying what the compiler / debugger / your program said should be enough in most cases. If the error happens at runtime, use -gl and disable function inlining when compiling so your program can generate a proper backtrace.
  
=== When I cycle the compiler, I get:The name specified is not recognized as an internal or external command, operable program or batch file.>& was unexpected at this time. ===
+
Often an image is also very useful. You can host images in https://imageshack.com/ and other similar websites and then post a link.
  
In the compiler dir exists an OS2 scriptfile named make.cmd. NT sees this also
+
Try to provide both a high-level overview of the problem ('''what goal you want to achieve''') as well as a more detailed view of the problem ('''how are you trying to achieve your goal'. Often, there is a much easier way of getting things done that you may not know about.
as a script file, so remove it since on NT we don't need it.
 
  
=== When I cycle the compiler, I get: make[3]: ./ppc1.exe: Command not found ===
+
Finally, make sure you have searched/read the relevant documentation (e.g. the [[FPC documentation]] and Lazarus wiki, see e.g. [[Lazarus Documentation]]. You should also [https://forum.lazarus.freepascal.org/index.php?action=search search the forums]: other people with may already have found solutions to similar problems. If you indicate you have already done a bit of homework, people will in general be much more willing to help.
  
I don't know why but somehow make has lost its path. Try to cycle with a
+
For more tips about asking questions the smart way, read this: http://catb.org/esr/faqs/smart-questions.html
basedir set like: make cycle BASEDIR=your_fpc_source_dir_herecompiler
 
  
=== When I try to make Lazarus I get:===
+
See also: [[Forum|How to use the forum]]
====make.exe: * * * interfaces: No such file or directory (ENOENT). Stop.make.exe: * * * [interfaces_all] Error 2 ====
 
You need to upgrade your make.
 
  
====makefile:27: *** You need the GNU utils package to use this Makefile.  Stop.====
+
== Version numbering ==
Make sure you didn't install FPC in a path with spaces in the name. The
+
See the [[Version Numbering]] page for an explanation of the branching and version numbering of Lazarus.
Makefile doesn't support it.
 
  
 +
== Problems/issues with old Lazarus/FPC versions ==
 +
Issues with old Lazarus/FPC versions and notes about upgrading are covered below.
  
 +
Often, the best solution is to upgrade; please see the various [[:Category:Release_Notes|Release Notes]]
  
===How can I give my program an XP look like lazarus has?===
+
=== Why is the linking so slow on Windows (Lazarus < 0.9.24)? ===
If you have a myprogram.exe then create a file which called myprogram.exe.manifest and copy-paste
+
{{Note|This problem was fixed in FPC 2.2 and Lazarus 0.9.24. Please update your Lazarus if you can. For older versions read text below.}}
this to the file:
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
 
<assemblyIdentity processorArchitecture="*" version="1.0.0.0" type="win32" name="myprogram"/>
 
<description>programom</description>
 
<dependency>
 
  <dependentAssembly>
 
    <assemblyIdentity
 
      type="win32"
 
      name="Microsoft.Windows.Common-Controls"
 
      version="6.0.0.0"
 
      publicKeyToken="6595b64144ccf1df"
 
      language="*"
 
      processorArchitecture="*" />
 
  </dependentAssembly>
 
  </dependency>
 
</assembly>
 
Voila! XP looks.
 
  
===When I run Windows program created in Lazarus it starts with a DOS window===
+
Generally speaking, compilation on Windows takes more time then other platforms because the GNU Linker utilized by Free Pascal is slow on this platform. This problem only affects Windows, and is only bad on relatively old computers (less then 1Ghz) and computers with little RAM (128MB or less).
Specify the -WG argument (Windows GUI) on the command line of the compiler or in the Lazarus IDE check the Windows GUI check box on the compiler options dialog box (Project menu -> Compiler Options -> Linking -> target OS Specific options.
 
  
== Licensing ==
+
Also, if you smartlink LCL the linking will be much slower. A study about this is located here: [[File size and smartlinking]]
  
=== Can I make commercial applications with Lazarus ? ===
+
Starting from FPC 2.2, an internal linker is used which decreases the linking time dramatically.
  
Yes, the LCL is licensed under the LGPL with an exception, which allows you to link to it statically without releasing the source of your application. Modifications and enhancements to the LCL must be distributed with source. Lazarus, the IDE, is licensed under the GPL.
+
=== Old Lazarus does not support Windows-style resources; converting lrs resources ===
 +
Older versions of FPC (and Lazarus based on it) don't support Windows (.rc/.res) resources, but only LRS files (Lazarus Resource files). See [[Lazarus Resources]]
 +
Since 0.9.30 Lazarus can use fpc resources. That means you can delete the lrs files for forms and replace the include directives <tt>{$I unit1.lrs}</tt> with <tt>{$R *.lfm}</tt>.
 +
=== Antivirus ===
 +
Excluding the Lazarus directory (and the directory/directories where your project/projects are) from on access virus scanning may help there.
  
=== Can I make commercial plug-ins for Lazarus ? ===
+
== See also ==
  
Yes, the IDEIntf part of the IDE is licensed under the LGPL with the same exception, so that shared data structures in this part will not force you to license your plug-in or design-time package under the GPL. We want everyone to be free to choose what plug-in to use, and not limit this choice. Therefore non-GPL compatible plug-ins are allowed. Note that it's not allowed to distribute a precompiled Lazarus with these non-GPL-compatible plugins included statically; however, we do not see this as a severe limitation, since recompiling Lazarus is easy.
+
* [[Mac Installation FAQ]] for macOS.
 +
* [[Unit not found - How to find units]] information on what to do when you get "unit not found" messages.
  
== Contributors and Comments ==
 
  
This page has been converted from the epikwiki [http://lazarus-ccr.sourceforge.net/index.php?wiki=LazarusFaq version].
+
{{AutoCategory}}
 +
[[Category:Lazarus]]
 +
[[Category:FAQs]]
 +
[[Category:Troubleshooting]]

Latest revision as of 07:37, 15 July 2023

English (en)

Light bulb  Note: This FAQ may be outdated in certain parts.

General

What is Lazarus?

Lazarus is a cross-platform integrated development environment (IDE) that lets you create visual (GUI) and non-visual Object Pascal programs, and uses the Free Pascal compiler to generate your executable. Its aim is write once, compile anywhere: you should be able to just recompile your program source code with Lazarus running on another operating system (or a cross compiler) and get a program that runs on that operating system.

For more details see Overview of Free Pascal and Lazarus

Why are the generated binaries so big?

The binaries are big because they include a lot of debug information necessary for using gdb (GNU Debugger). A debugger is a program that is used to test your code. It uses the extra-information stored in your binary to test it. But once your program is working well, you may delete those infos and reduce the size of the binary.

Quick guide to Lazarus/FPC application size reduction

  • 1. Project|Compiler Options|Code|Smart Linkable (-CX) -> Checked
  • 2. Project|Compiler Options|Linking|Debugging| Uncheck all except Strip Symbols From Executable (-Xs)
  • 3. Project|Compiler Options|Linking|Link Style|Link Smart (-XX) -> Checked
Light bulb  Note: only do this if you don't need to run the debugger. For more details, see Size Matters

Lazarus executable size starts big, but grows very slowly, because of the way the LCL is designed, and its use of certain Free Pascal features (RTTI). Projects that don't use the LCL are much smaller (this is similar to some non-GUI C++ frameworks). This typically requires more manual coding though.

Exclude image readers See Lazarus 1.10.0 release notes#LCL Changes If your app does not use images compressed in one of those formats, then you can exclude it.

Do I need ppc386.cfg or fpc.cfg?

You only need fpc.cfg. This way the compiler knows where to find the libraries.

How do I compile Lazarus?

Do something like this:

cd lazarus
make clean all

If you want to build Lazarus for different widgetset eg. Qt (supported on Linux, Windows and OSX) then use the LCL_PLATFORM argument:

cd lazarus
make clean all LCL_PLATFORM=qt

Is it possible to build Lazarus projects without the Lazarus IDE?

See Using_the_LCL_without_Lazarus

How do I build other Free Pascal programs that use LCL without the Lazarus IDE?

See Using_the_LCL_without_Lazarus

What version of FPC is required?

Any Lazarus version compiles and works with 2 latest FPC release versions. FPC release cycle is slow and 2 latest versions typically span over few years.

Lazarus trunk also supports FPC trunk.

  • Lazarus 1.0.8 requires at least FPC 2.6.2.
  • Lazarus 1.0 requires at least FPC 2.6.0.
  • Lazarus 2.x requires at least FPC 3.0.0
  • Lazarus 3.0 requires at least FPC 3.2.0

I can't compile Lazarus

  1. Check if the compiler is the correct version
  2. Check if the (fpc) libraries are from the same version
  3. Check if the compiler installation path has spaces in it. Make sure it doesn't!
  4. Check if you have a fpc.cfg and no old ppc386.cfg
  5. Check also the OS-dependent FAQs
  6. If you're still stuck, ask on the forum or Lazarus mailing list

How to embed a small file in the executable, without the need of a separate file? How to embed a resource?

Both Lazarus resource and Windows-type/FPC resources are supported. See Lazarus Resources.

What is the meaning of the various file extensions used by Lazarus?

The Lazarus Tutorial#The Lazarus files explains some extensions by an example. Here is a brief list:

extension filetype description
.lpi Lazarus Project Information contains project-specific settings like compiler settings and needed packages. stored in XML
.lps Lazarus Program Session Personal data like cursor positions, source editor files, personal build modes. stored in XML
.lpr Lazarus Program Pascal source of main program.
.lfm Lazarus Form Form configuration information for all objects on a form (stored in a Lazarus-specific textual format, similar to Delphi dfm; the actions are described by Pascal source code in a corresponding *.pas file)
.pas
.pp
.p
Pascal code Pascal code typically for a form stored in a corresponding *.lfm file
.lrs Lazarus Resource Generated Lazarus Resource file; not to be confused with a Windows resource file.

This file can be created with lazres tool (in directory Lazarus/Tools) using commandline: lazres myfile.lrs myfile.lfm

.ppu Compiled unit Compiled source code created by the Free Pascal compiler for each unit and program.
.o Object file created by the compiler, every ppu file has a corresponding o file, needed by the linker.
.lpk Lazarus package information package-specific settings, like compiler settings and needed packages; stored in XML
.lrt Lazarus Resourcestring table Lazarus Resourcestring table created when saving a lfm file and i18n is enabled. It contains the TTranslateString properties of the lfm. Do not edit them, they are overwritten.
.rst Resourcestring table Resourcestring table created by the compiler for every unit with a resourcestring section. Do not edit them, they are overwritten.
.po gnu gettext messages When i18n is enabled the IDE creates/updated the .po files with the resourcestrings from the rst and lrt files.

Why are TForm.ClientWidth/ClientHeight the same as TForm.Width/Height

The TForm.Width/Height do no include the frame, because there was no way to retrieve the frame size on all platforms. Without a reliable way, the LCL would move the forms around on the screen or resize them endlessly.

Eventually it will be changed when there is a reliable way to get the size and position of a window with its frame on all platforms. To keep compatibility with older LCL forms, a version number and some extra methods will be added.

Errors

Platform specific errors/problems are also covered in sections below.

'Fatal: Circular unit reference between a and b'

A common thing happened to a new user when one wants to create two forms referencing each other's properties. The error above only happens to uses clause of interface section, thus it's OK to put it in implementation section. Example:

This one causes error:

unit a;

interface

uses b;

implementation

end.
unit b;

interface

uses a;

implementation

end.

But this one doesn't:

unit a;

interface

implementation

uses b;

end.
unit b;

interface

implementation

uses a;

end.


In some cases the minimal base class method might be suitable.

Separate one class into a minimal base class (what the other needs) and derive it for the rest of the implementation.


unita: uses unitb

  type
    ClassA = class(BaseClassA)
    // rest of ClassA
    end;

unitb:

  type
    ClassB = class;  //forward declaration

    BaseClassA = class
    // references ClassB
    end;
       
    ClassB = class
    // references BaseClassA
    end;

Discussion: https://forum.lazarus.freepascal.org/index.php/topic,25667.msg156115.html#msg156115

When I do var mytext: text; to declare a text file, I get "Unit1.pas(32,15) Error: Error in type definition". How can I fix this?

The TControl class has a Text property. In a method of a form, that has higher visibility, the Text type from the system unit. You can use the TextFile type, which is just an alias for the Text type or you can add the unit to the type definition.

var
  MyTextFile: TextFile;
  MyText: System.Text;

A similar name clash exists with assigning and closing a text file. TForm has a assign and a Close method. You can use AssignFile and CloseFile or add the unit name System.

I get an error when using Printer.BeginDoc

The unit Printers must be added to the uses section and the Printer4Lazarus package must be added to your project requirement in the IDE under: Project > Project Inspector > Add > New Requirement > Package Name.

If the Printer4Lazarus package is not in the list when opening the dropdown box it must be installed. The package is part of the Lazarus installation and can be found in: [lazarus installed directory][/|\]components[/|\]printers.

If you used the default installation directories [lazarus installed directory] is:

Operating system Lazarus installed directory
FreeBSD /usr/local/share/lazarus
Linux /usr/lib/lazarus
macOS /Library/Lazarus/
Windows c:\lazarus

The same solution also applies to the exception you can get when referencing Printer.Printers.

When I try to compile a project, I get an error message "Cannot find Unit ..."

Please see Unit not found - How to find units

For information on the error "Cannot find unit interfaces", see the next section.

When I try to compile a project, I get an error message "Cannot find Unit interfaces"

This error means that the compiler can not find the file 'interfaces.ppu' or the file was found, but it is wrong or outdated (the .ppu file date code is older than the date code of the compiler itself). Testing the compiler option settings can help debug these issues, via Project: Compiler Options... (use the Test button at the bottom of the dialog). This test also lets you check that the {TargetCPU} and {TargetOS} variables are set properly.

The interfaces unit can be found in {LazarusDir}\lcl\units\{TargetCPU}-{TargetOS}\{LCLWidgetSet}\interfaces.ppu. For example: /home/username/lazarus/lcl/units/i386-linux/gtk/interfaces.ppu.

It is normal to have multiple versions of interfaces.ppu (in the proper directories) to allow compiling with different widgets.

If the interface.ppu file is in the folder matching the OS and CPU you selected in the project preferences, and you get this error, you are using a different compiler / RTL for compiling your project than you used for compiling your Lazarus IDE, or the libraries need to be recompiled to give the .ppu files newer compilation dates.

You can do one of the following:

  1. Set the compiler in the Environment Options to the one you used to compile Lazarus. Also look carefully in the Environment Options to see if you are using the correct paths for the Lazarus directory and the FPC sources directory. Check that there is only one version of the compiler configuration file fpc.cfg - it should reside in /etc/ for Linux/Unix systems or in the same directory as the fpc compiler for Windows systems. Try to run "fpc -vt bogus" to check which fpc.cfg is being used in your system. Rogue copies often creep in if you have updated your compiler to a new version; they may be found in your home directory or in the same directory as the one in which you built your new compiler. DELETE THESE!
  2. Rebuild the LCL (or Lazarus completely) with the compiler selected in the Environmnent Options. You can do this with Tools -> Build Lazarus. Before doing this, check the current settings in Tools -> Configure Build Lazarus.
  3. You may also try to change the widgetset currently selected for the project. For example, the sample project "objectinspector" that comes with Lazarus is set to gtk by default. Compiling this project will surely give you "Can't find unit interfaces" in Windows platform. Changing widgetset to default(Win32) in Project Options | Compiler Options... should fix this issue.

When I compile a project, that uses a LCL unit, I get a linker error

Here is an example for such a linker error:

/path/to/lazarus/lcl/units/x86_64-linux/wsimglist.o: In function `REGISTERCUSTOMIMAGELIST':
/path/to/lazarus/lcl//widgetset/wsimglist.pp:266: undefined reference to `WSRegisterCustomImageList'
  • Make sure yor project uses the package LCL. You can check this in the project inspector.
  • Make sure unit "interfaces" is used as one of the first units of your program.
Light bulb  Note: These functions are implemented by the LCL backends. By adding the unit interfaces, you link a LCL backend into your program.

At the line :{$R *.DFM} How can I solve this problem (Lazarus with FPC < 2.4.0)?

Lazarus (or better Linux) doesn't know about resources, so you can't use them in the way Delphi/Win32 does. However Lazarus uses a method pretty compatible with this. You can still use your Delphi layouts (.dfm files) if you use the following steps:

  • You need a textual version of the .dfm files. D5 and higher are doing this by default. If you have older files: Alt+F12 to see the layout as text and paste/copy. When you have a text .dfm file, just copy it to a .lfm file.
  • Create a file with lazres (in lazarus/tools) lazres yourform.lrs yourform.lfm
  • Add the following initialization section to
initialization
{$I yourform.lrs}

Please keep in mind that not all properties in the dfm are supported yet by Lazarus, so you might get a crash.

Edit: Since FPC 2.4.0, Delphi style resources are supported, so you don't need to change anything. Even Lazarus SVN already uses it as default projects. Note: it's still advised that you use Lazarus' Delphi project converter as there might still be unsupported properties.

'Identifier not found LazarusResources'

When creating a form Lazarus automaticaly add some extra units to the uses section of your form unit. During the conversion of a delphi unit to a Lazarus unit this does not happen. So you need to add LResources to the Uses section of your form unit.

When accessing events of objects, e.g., the onclick event of a button, I get the following error. ERROR unit not found: stdCtrls

Make sure, in the Project -> Project Inspector, that your project depends on the package "LCL" and that you have installed the FPC sources.

Lazarus is the IDE and the visual components library LCL. All other stuff, like IO, Database, FCL and RTL are provided by FPC. The IDE needs the paths to all sources.

The FPC source path can be set via: Environment -> Environment Options -> Files -> FPC source directory

'Fatal: Internal error XXXXYYZZW'

An internal error is a compiler error that is not expected to happen (but is prepared to easily track down the problem if happens by giving code XXXXYYZZW). Every internal error is a bug, thus it's advised to report to the bugtracker (with small example that can demonstrate the internal error) when one gets it.

Fatal: Cannot find [...] used by [...], incompatible ppu=[filename], package [package name]

When the compiler gives the message "Cannot find A used by B", Lazarus checks what pas/pp/ppu files are in the search path, and if there is a ppu file it inserts "incompatible ppu=filename, package".

Explanation: FPC cannot use this ppu for one of these reasons:

  • it was compiled with another FPC version;
  • it was compiled with (depends on) some other ppu files that are not in the search path;
  • you misconfigured some search path(s).

Without knowing how you installed FPC + Lazarus, I'd be tempted to delete both and start again (make sure to delete the fpc.cfg file).

Lazarus cannot open a project if last character of the path to it is a space

If you try to open a project like /home/bart/space /test.lpi (note the space just before /test.lpi), the Lazarus IDE will give an error saying it cannot find /home/bart/space /test.lpi.

This is a known limit of the IDE, which is caused by the fact that the IDE a.o. has to handle paths that users have supplied in edit controls, which have to be stripped from surrounding spaces. This limitation in no way affects user programs written in FPC/Lazarus. Avoid such pathnames for projects.

strToFloat - EConvertError: "0.nnn" is an invalid float

The "0.nnn" can be any floating point number. The problem is that your locale settings (eg DE Germany) are expecting a comma to be the decimal separator in numbers and not a decimal point. The solution is to add this to your code: DefaultFormatSettings.decimalSeparator := '.'; to override your locale's decimal separator. Alternatively, instead of strToFloat and floatToStr, use the Pascal intrinsics val and str - they always need a decimal point.

Debugger

See also GDB Debugger Tips.

How do I set up/configure for debugging

Setup the debugger

How can I inspect properties?

You have to use FPC 2.4 or newer.

If you compile your application using -gw (dwarf debug info), you should be able to inspect properties.

Light bulb  Note: This is only true for properties that map directly to a variable (the "read" declaration points to a member, not a function).

If your property returns the value of a function it is very dangerous to evaluate/inspect it. It would require this function to be called, and very often it would change the values of some of your variables. This would mean it would alter the state of your application in the debugger, and any further code-execution, debugging or inspections would return incorrect results.

The optional ability to explicitly inspect the results of functions (with the risks described), and therefore calling code from the debugger is not yet implemented

Why does the debugger not show some Variables/Structures ("no such symbol"/"incomplete type")

For problems debugging:

  • properties
  • Array of ... (Dynamic Array)
  • Variables in Nested Procedures
  • "no such symbol in context"
  • "incomplete type"

Please see GDB_Debugger_Tips and the and FpDebug#Properties

How can I debug FCL components from packages with Lazarus

FCL components and classes are built without debug information by default and as a result, gdb cannot access component methods or properties. To build package components they must be rebuilt with a debug-line information "-gl" switch.

This example assumes you have a Linux distribution with /usr/local/ installation prefix and that the Database package fcl-db is what is needed to contain debug-line information. While the fcl-db is used in this example, you may issue this make command from ANY of the included packages.

Before you begin, you need to locate your FPC path by examining your FPC configuration file. The file (fpc.cfg) is located at /etc/fpc.cfg. Display the contents of fpc.cfg and find your fpc installation path. Look for a line starting with -Fu in the fpc.cfg:

-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/*

Make scripts are installing units into INSTALL_PATH/lib/fpc/$fpcversion/units/$fpctarget/, so you must be sure that /usr/local is the installation path, and should be assigned to INSTALL_PREFIX, otherwise the Make scripts will place units where they don't belong or the Make script will fail.

  1. Open a shell terminal
  2. cd /user/local/share/src/fpc-2.3.1/fpc/fcl-db/
  3. sudo make clean all install INSTALL_PREFIX=/usr/local OPT=-gl
Light bulb  Note: INSTALL_PREFIX parameter should be properly configured for units to be installed.

In the sample below /usr/local is a default fpc path for Linux, but may vary on other OSes.

make clean all install INSTALL_PREFIX=/usr/local OPT=-gl

Finally, after rebuilding any FCL units you may want to rebuild LCL as well.

Problems with GDB on Mac

Lazarus has now support for lldb on Mac. See Configuring the lldb debugger.

If you want to use gdb, you can find some info here: GDB tips for Mac

How can I use a log file for debugging?

Lazarus provides a basic log framework (style debugln(...) ) in the unit LazLogger. See that page for more details.

How can I use a Log-file for debugging the IDE itself?

Lazarus itself uses LazLogger.

This means that you can run Lazarus with

--debug-log=lazarusdebuglog.txt

If this is not sufficient: in the IDE the extent of the information that is logged can be controlled with --debug-enable. See --help for a list of keywords, or install the package IdeLazLogger.

If you want output on a console (most useful for Windows), add the option -WC in the Tools / Configure "Build Lazarus" options. Then rebuild Lazarus.

See also Console Mode Pascal#Run in IDE with redirected output

Contributing / Making Changes to Lazarus

I created a Patch to dock the IDE Messages form on the "Source Code Editor" form (at bottom)

Such patches will not be applied, because they only implement a small part of the needed docking. The goal is to create a complete dock manager and use that. A complete dock manager can dock all IDE windows and it allows to let the user define how to dock. For example dock the messages window above or below the source editor — or not at all. For instance,

+-------------------++--+
|menu               ||  |
+-------------------+|  |
+--++---------------+|  |
|PI|| Source Editor ||CE|
+--+|               ||  |
+--+|               ||  |
|  |+---------------++--+
|OI|+-------------------+
|  ||messages           |
+--++-------------------+

The dock manager can store the layout and restore it on next load. Preferably the dock manager can dock in pages too. The dock manager does not need to use drag and drop. All patches implementing docking without a dock manager makes it harder to implement a real dock manager and will be rejected.

An example for such a dock manager is the package anchordockdsgn

I have fixed/improved Lazarus. How can I add my changes to the official Lazarus source?

Create a patch and send it to the developers. For details, see Creating A Patch.

How can I install more than one copy of Lazarus?

Please see Multiple Lazarus

How can I become a Lazarus developer and access management in the SVN and bug-tracker?

First of all, you must learn about Lazarus, to prove your knowledge and skill. Start by reading the Lazarus Documentation wiki article, read the Lazarus source code, giving a look at the Lazarus Bug-Tracker, fix some bugs, and if you think you are ready, contact the developers on the mailing list.

Where is ... defined

Virtual key constants

Virtual key constants are defined in LCLType. Add LCLtype to your uses.

Using the IDE

How can I use "identifier completion"?

You can invoke identifier completion by pressing [ctrl][space]. Under the menu item Environment -> Editor Options -> Code Tools -> Automatic Features you can set how quick this should happen automatically.

Can I change the code editor font and colours?

Yes, see the menu item Tools -> Options and use the Editor/Display and Colors sections. On Windows you may find that the default Courier (and some other typefaces) are either too sharp or too soft, either selecting/deselecting 'Disable anti-aliasing'. TrueType fonts are an improvement, such as the free "Bitstream Vera Sans Mono" font available from [1]. (To install a new font, unzip and copy the files into a suitable folder. In Windows XP you will need to use the Fonts section of the Control Panel. In Windows 7 you may select all the font files, right-click and find an Install option in the pop-up menu)

How can I disable specific compiler warning messages?

To disable specific compiler warning messages you can either insert a {$WARN number OFF} directive in your code or use FPC's option -vm<x>. You can find details for these in FPC's Programmer's guide and Appendix A of the User's guide.

What are the IDE command line options?

See Lazarus command line options.

Linux

Typing in edit fields generate duplicate letters

This is more likely to happen under Ubuntu and Ubunto derived distros, and with GNOME Desktop but other distros/Desktop environments can be affected too.

The problem is originated by bugs in the ibus Input Method System. Unfortunately Ibus is the default input method of GNOME desktop.

If you don't know what an IM is, this means that you do not need it, and therefore the easiest way is to disable IM's at all.

In order to do that you have a number of options, namely:

  • 1 - Disable (or set to "none") the Input Method in System Settings->Preferences->Input Method
  • 2 - Add the three following lines in /etc/profile (system wide)
export GTK_IM_MODULE=gtk-im-context-simple
export QT_IM_MODULE=simple
export XMODIFIERS=@im=none
  • 3 - Add a file named input_method.sh containing just the 3 lines above in /etc/profile.d (system wide)
  • 4 - Add the 3 lines above in the home directory ~/.xprofile (per user). If there's no ~/.xprofile in your home directory, you should create one.
  • 5 - Create a Lazarus launching script containing the same 3 lines. (affects only Lazarus)

Methods 1 and 2 may not survive after a system update, while 3,4 and 5 will.

Be aware that both GTK and QT applications may change dynamically the IM. If you experience the problem in an apparently random way, chances are good that some other application is enabling again an IM and fails to set to default when terminates. If such is the case method 5 is the only one suitable.

You may find more information about Input Methods, and how to deal with them in:

https://fedoraproject.org/wiki/I18N/InputMethods (This is Fedora specific but most informations apply in general)

http://www.pinyinjoe.com/linux/ubuntu-12-chinese-setup.htm (This is Ubuntu specific, but again most informations apply in general. It explains how to enable IM but the info can be used also to disable it)

How can I debug on Linux without the IDE?

First of all you need a debugger. gdb is the standard debugger under linux and there are several GUI-frontends available. One common frontend is ddd, which is part of most common distributions. To compile lazarus/lcl with debug-information you should then use the following commands to start a debug session:

make clean; make OPT=-dDEBUG
ddd lazarus

Be warned, however, that ddd is not as comfortable as, e.g., the Lazarus debugger, especially if it comes to view the contents of a variable you have to take into account that ddd/gdb are case sensitive whereas Pascal is case-insensitive. Therefore, you have to type all variable names in uppercase to see their contents. For more information see the fpc-manuals.

I can debug now but ddd does not find my sources or complains that they contain no code. What's that?

This is a path-related problem with either gdb or ddd. You can avoid this by

  • Use the "Change directory" command from the ddd menu and choose the directory where the sources are located. The drawback of this method is that you now can't use the source of the program you started with (e.g. lazarus). Thus it may be neccessary to change the directory multiple times.
  • In ddd goto [Edit] [gdb-settings] and set the search-path
  • Create a $(HOME)/.gdbinit file like:
     directory /your/path/to/lazarus
     directory /your/path/to/lazarus/lcl
     directory /your/path/to/lazarus/lcl/include

I receive an error during the linking that states /usr/bin/ld: cannot find -l<some lib>

For example:

 /usr/bin/ld: cannot find -lgdk

This means an external library was not found. In the above case under Linux it means the libgdk.so or libgdk.a was not found. Normally this means, you forgot to install the development package of this library. In the case of gdk the package is called under the Fedora Core distribution: 'gtk+-devel-1.2.10-33'.

Package Based Distributions
You need to install the package that provides the lib<somelib>.so or lib<somelib>.a files. Dynamic libs under linux have the extension .so, while static libs have the extension .a. On some Linux distro's you have installed the package (rpm, deb) <packagename> which provides <some lib>, but you also need the development package (rpm, deb), normally called <packagename>-dev, which contains the .a (static lib) and/or the .so (dynamic lib).
Some distributions have commands to find which package contains a file:
Mandriva
urpmf lib<somelib>.so
will list all packages containing the file named lib<somelib>.so, you'll have to install those ending in -devel
Debian
install the apt-file utility (apt-get install apt-file) then
apt-file search lib<somelib>.so
will list all packages containing the file named lib<somelib>.so, you'll have to install those ending in -dev
SuSE
SuSE installs the gtk devel libs under /opt/gnome/lib (or /opt/gnome/lib64 for 64 bits), which is not in the standard lib path. Simply add it to your /etc/fpc.cfg. (-Fl/opt/gnome/lib).
Source Based Distributions and Manual Compilation (LFS)
Make sure that there is a lib<somelib>.a in the path, and that it contains the right version. To let the linker find the dynamic library, create a symlink called lib<some lib>.so to lib<some lib><version>-x,y.so if necessary (and/or for static lib; lib<some lib>.a to lib<some lib><version>-x,y.a).
FreeBSD : As source based distro's, and also make sure you have -Fl/usr/local/lib in your fpc.cfg and/or Lazarus library path. Keep in mind that GTK1.2 has "gtk12" as package name under FreeBSD. (same for glib) NOTE: This has changed as of late. Newest ports have gtk-12 and glib-12 as well. You might stumble on this problem, since FPC requires the "-less" ones, you will need to symlink them like this:
# as root
cd /usr/local/lib && ln -s libglib-12.so libglib12.so
cd /usr/X11R6/lib && ln -s libgtk-12.so libgtk12.so
cd /usr/X11R6/lib && ln -s libgdk-12.so libgdk12.so
NetBSD : As source based distro's, and also make sure you have -Fl/usr/pkg/lib in your fpc.cfg and/or Lazarus library path
Fedora : In the "add/remove software" panel search for: "gtk2-devel", "glibc-devel" (see here), "libx11-devel"

I receive a warning during the linking that states: Warning: "crtbeginS.o" (or "crtendS.o") not found

The actual filename may also be "crtbegin.o" or "crtend.o"
In most cases linking will not fail.
Here's how to find where that file is (you need to have gcc installed, and gcc needs to target the same architecture as fpc), and tell the fpc (which tells the linker):

bart@simenon ~ $ gcc --print-file-name crtbeginS.o
/usr/lib/gcc/x86_64-linux-gnu/5/crtbeginS.o

Add the path into fpc.cfg:

# path to the gcclib
#ifdef cpui386
#-Fl/usr/lib/gcc/x86_64-linux-gnu/5  if you have a 32-bit fpc: fill in the correct path here
#endif
#ifdef cpux86_64
-Fl/usr/lib/gcc/x86_64-linux-gnu/5
#endif

Note: On Linux the default (external) linker is ld. This is part of the linux distribution and not part of, or built with, FreePascal.

How can I convert a Kylix 2 project into a Lazarus project?

Nearly the same way as converting a Kylix project into a Delphi/VCL project.

The LCL (Lazarus Component Library) tries to be compatible to Delphi's VCL. Kylix's CLX tries to be QT compatible. Here are some general hints:

  • Rename all used CLX Q-units like QForms, QControls, QGraphics, ... into their VCL counterparts: Forms, Controls, Graphics, ...
  • Add LResources to the uses section of every form source
  • Rename or copy all .xfm files to .lfm files.
  • Rename or copy .dpr file to .lpr file.
  • Add "Interfaces" to the uses section in the .lpr file.
  • Remove {$R *.res} directive
  • Remove {$R *.xfm} directive
  • Add {$mode objfpc}{$H+} or {$mode delphi}{$H+} directive to .pas and .lpr files
  • Add an initialization section to the end of each form source and add an include directive for the .lrs file (Lazarus resource file):
initialization
{$I unit1.lrs}
The .lrs files can be created via the lazres tool in: (lazarusdir)/tools/lazres.
For example: ./lazres unit1.lrs unit1.lfm
  • Fix the differences. The LCL does not yet support every property of the VCL and the CLX is not fully VCL compatible.
  • To make it more platform independent, reduce unit libc (which is deprecated) references and substitute with native FPC units like baseunix/unix as much as possible. This will be necessary to support other targets than linux/x86 (including macOS, FreeBSD and Linux/x86_64)

When compiling lazarus the compiler can not find a unit. e.g.: gtkint.pp(17,16) Fatal: Can't find unit GLIB

1. Check a clean rebuild: do a 'make clean all'

2. Check if the compiler has the correct version (2.0.4 or higher)

3. Check if the compiler is using the right config file. The normal installation creates /etc/fpc.cfg. But fpc also searches for ~/.ppc386.cfg, ~/.fpc.cfg, /etc/ppc386.cfg and it uses only the first it finds.

Hint: You can see which config file is used with 'ppc386 -vt bogus'
Remove any ppc386.cfg as it is really obsolete.

4. Check if the config file (/etc/fpc.cfg) contains the right paths to your fpc libs. There must be three lines like this:

   -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
   -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl
   -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
The first part of these paths (/usr/lib/fpc) depends on your system. On some systems this can be for example /usr/local/lib/fpc/... .
Hint: You can see your searchpaths with 'ppc386 -vt bogus'

5. Check that the config file (/etc/fpc.cfg) does not contain search paths to the lcl source files (.pp, .pas):

 forbidden: -Fu(lazarus_source_directory)/lcl
 forbidden: -Fu(lazarus_source_directory)/lcl/interfaces/gtk
If you want to add the lcl for all your fpc projects, make sure that the two paths look like the following and are placed after the above fpc lib paths:
 -Fu(lazarus_source_directory)/lcl/units/$fpctarget
 -Fu(lazarus_source_directory)/lcl/units/$fpctarget/gtk

6. Check if the missing unit (glib.ppu) exists in your fpc lib directory. For example the gtk.ppu can be found in /usr/lib/fpc/$fpcversion/units/i386-linux/gtk/. If it does not exists, the fpc lib is corrupt and should be reinstalled.

7. Check if the sources are in a NFS mounted directory. In some cases the NFS updates created files incorrectly. Please, try to move the sources into a non NFS directory and compile there.

8. If you are still not succeeded try to use samplecfg script as follows:

# cd /usr/lib/fpc/version/

# sudo ./samplecfg /usr/lib/fpc/\$version /etc

Light bulb  Note: Do not a slash ("/") after etc, because if you do, the system will create a folder /etc/fpc.cfg/fpc.cfg. In fact, we want samplecfg to make a file /etc/fpc.cfg, not the folder /etc/fpc.cfg.

I have installed the binary version, but when compiling a simple project, Lazarus gives: Fatal: Can't find unit CONTROLS

Probably you are using a newer fpc package, than that used for building the lazarus binaries. The best solution is to download the sources and compile lazarus manually. You can download the source snapshot or get the source via svn:

bash
svn checkout http://svn.freepascal.org/svn/lazarus/trunk lazarus
cd lazarus
make clean all

Make sure that Lazarus get the new source directory: Environment->General Options->Files->Lazarus Directory Top

Lazarus compiles, but linking fails with: libgdk-pixbuf not found

Install the gdk-pixbuf library for gtk1.x:

Where to find the gdk-pixbuf library:

RPMs: https://rpmfind.net/linux/rpm2html/search.php?query=gdk-pixbuf&submit=Search+...&system=&arch=

Debian packages: libgdk-pixbuf-dev

Sources: ftp://ftp.gnome.org/pub/gnome/unstable/sources/gdk-pixbuf/

Ubuntu 8.10:

If you are compiling Lazarus with GTK 2.0 you'll get a "libgdk-pixbuf2.0" not found error. Just install libgtk2.0-dev using apt on this way:

apt-get install libgtk2.0-dev

I have SuSE and I get /usr/bin/ld: cannot find -lgtk Error: Error while linking

Older SuSE versions (before SuSE 11) install the gtk devel libs under /opt/gnome/lib (or /opt/gnome/lib64 for 64 bits), which is not in the standard lib path. Simply add it to your /etc/fpc.cfg (-Fl/opt/gnome/lib).

I have Kubuntu and I get /usr/bin/ld: cannot find -lgtk-x11-2.0

You can either use the QT or the GTK2 backend. Default is GTK2. For GTK2 install the kubuntu package libgtk2.0-dev.

Lazarus crashes with runtime error 211 after I installed a component

After I installed a component, Lazarus crashes with the following message:

Threading has been used before cthreads was initialized.
Make cthreads one of the first units in your uses clause.
Runtime error 211 at $0066E188

How can I fix this?

Your freshly installed component is using threads. FPC on *nix doesn't automatically include threading support, but it must be intialized. This initialization is done in the cthreads unit. Every application using the component needs to add this unit to the uses clause of the main program. Lazarus itself is no exception. This can be done in two ways:

1) Open the package. In the package editor click on Options. Under page Usage add to the custom options -dUseCThreads. Then rebuild the IDE. This way the cthreads unit will be automatically used by the IDE under unix and the cthreads are initialized.

2) In order to avoid modifying package, an FPC compiler option could be used directly. Open menu Tools->Configure "build Lazarus". "Configure build Lazarus" dialog will be shown; in field "Options:" type -Facthreads and then press "OK" button. The next step is to install the package. Lazarus will be built with option -Facthreads which means that it will treat main program as if unit cthreads where first in uses clause.

Hint: Maybe your old (non-crashing) Lazarus executable is stored as lazarus.old in the same directory as the crashing Lazarus executable.

See also Multithreaded Application Tutorial#Units needed for a multithreaded application

When I run a program with threads I get runtime error 232

The complete error message is:

This binary has no thread support compiled in.
Recompile the application with a thread-driver in the program uses
clause before other units using thread.
Runtime error 232

Solution: Add cthreads as first unit to the uses clause of your main program, usually the .lpr-file.

I have Ubuntu Breezy/Mandriva KDE3 and my fonts in Lazarus IDE look too big

If Lazarus is compiled with Gtk1.2, the settings in Gnome Preferences/Font don't have any effect as they are related to Gtk2. You could try this solution: Create a file named .gtkrc.mine in your home directory (if it's not already there) and add these lines to it:

style "default-text" {
       fontset = "-*-arial-medium-r-normal--*-100-*-*-*-*-iso8859-1,\
                  -*-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
}

class "GtkWidget" style "default-text"

If this is not enough try and create also a .gtkrc symlink to .gtkrc.mine . It worked in this way under Xubuntu 7.10, Mandriva 2009.0 KDE3.

How can my gtk programs use custom rc files?

Option a) Name the rc file yourprogram.gtkrc and put it in the same directory where the executable is.

Option b) Use unit GtkInt and call GTKWidgetSet.SetRCFilename('your_preferred_rc_file'); Best done before Application.Initialize in the .lpr file with {$IFDEF LCLGtk}.

Option c) Use unit gtk2 and call gtk_rc_parse('your_rc_file')); and gtk_rc_reparse_all;.

I have Ubuntu and I cannot compile for Gtk2 due to missing libraries

Ubuntu has a problem with not creating all the symbolic links that you'll need even when the libraries are installed. Make sure that all missing libraries when trying to link for Gtk2 have their appropriate links. For instance, you might need to do:

cd /usr/lib
sudo ln -s libgdk-x11-2.0.so.0 libgtk-x11-2.0.so

Make sure that the [whatever].so symbolic links are created and point to the actual libraries.

Lazarus runs differently with Linux vs. Windows. What do I need to know?

If you use readln(); and writeln(); for your input and output the console window (sometimes called terminal window) is not going to pop up as it does with Windows. You will need to access this window with View - Debug Windows - Terminal Output. Unlike with Windows you can not use backspace to correct typing errors. The 'Enter' key on the numeric keypad may not work either, depending on the widgetset the IDE was built for. Type carefully!

Because Linux is case sensitive you will need to take care that you pay attention to case when referencing or accessing files.

Windows

When I cycle/rebuild the compiler, I get

The name specified is not recognized as an internal or external command, operable program or batch file.>& was unexpected at this time

In the compiler directory there is an OS2 scriptfile named make.cmd. Different versions of Windows also see this as a script file, so remove it since what is needed for OS2 becomes a hindrance on Windows.

make[3]: ./ppc1.exe: Command not found

Somehow make has lost its path (reason unknown). Try to cycle with a basedir set like:

make cycle BASEDIR=your_fpc_source_dir_herecompiler

When I try to make Lazarus I get:

make.exe: * * * interfaces: No such file or directory (ENOENT). Stop.make.exe: * * * [interfaces_all] Error 2

You need to upgrade your make.

makefile:27: *** You need the GNU utils package to use this Makefile. Stop.

Make sure you didn't install FPC in a path with spaces in the name. The Makefile doesn't support it.

How can I give my program an XP look like Lazarus has?

Project -> Project Options -> Check 'Use manifest to enables themes'.

When I run Windows program created in Lazarus it starts with a DOS window

Specify the -WG argument (Windows GUI) on the command line of the compiler or in the Lazarus IDE check the Windows GUI check box on the compiler options dialog box (Project menu -> Compiler Options -> Config and Target -> target OS Specific options.

macOS

Why does compiling a project fail with 'unknown section attribute: no_dead_strip'?

Dead code stripping is not supported by the assembler and linker before Xcode 1.5 (available for macOS 10.3.9). Disable the compiler options:

  • Code > Unit style > Smart linkable (-CX)
  • and Linking > Link Style > Link smart (-XX)

Xcode 3.1 and later

The macOS linker in Xcode 3.1 (2007, Leopard 10.5) and later does not support stripping the symbol table attached to the output of the assembler and link editor. The linker supported stripping, for 32 bit executables only, up to Xcode 2.5 (2005, Tiger 10.4).

You will need to manually run the strip command line utility instead after compiling your executable.

Debugging

Please see here for debugger issues under macOS

Licensing

Can I make commercial applications with Lazarus?

Yes, the LCL is licensed under the LGPL with an exception, which allows you to link to it statically without releasing the source of your application. Modifications and enhancements to the LCL must be distributed with source. Lazarus, the IDE, is licensed under the GPL. The LCL consists only of the code in the directory named "lcl", other code may not be covered by this statement.

Why are some components restricted from usage in commercial application?

Lazarus comes with additional components, that were developed by third parties. Those are under various other Licenses. If you wish to use them you need to see the License within the source files of those packages. Most of those 3rd party components are in the directory "components".

How do I know if a Component is part of the LCL?

All LCL units are in the directory "lcl". A list of units belonging to the LCL can be found here. If your code uses units not listed on this page, you may have used a component that is not part of the LCL.

Can I make commercial plug-ins for Lazarus?

Yes, the IDEIntf part of the IDE is licensed under the LGPL with the same exception, so that shared data structures in this part will not force you to license your plug-in or design-time package under the GPL. You are free to choose a plug-in of any license; we don't want to limit your choice. Therefore non-GPL compatible plug-ins are allowed. Note that it's not allowed to distribute a precompiled Lazarus with these non-GPL-compatible plugins included statically; however, we do not see this as a severe limitation, since recompiling Lazarus is easy.

Using the Forum

What is the correct way to ask questions in the forum?

First and most important: always mention which Lazarus version, Free Pascal version, Widgetset, CPU Architecture and Operating System (with full version) that you are using! Don't just say that you are using "the latest version"; please state the exact version number. For snapshots, the revision number and/or date are also important.

When asking a programming question, always try to include some source code which demonstrates the problem. Please surround your code with [code=pascal]...[/code] tags (or use the Insert code button in the forum post editor toolbar). You can attach complete programs as zip files if you want. Use Lazarus/Project/Publish Project to help with that.

If you get an error on your code, always specify what the error is. Simply copying what the compiler / debugger / your program said should be enough in most cases. If the error happens at runtime, use -gl and disable function inlining when compiling so your program can generate a proper backtrace.

Often an image is also very useful. You can host images in https://imageshack.com/ and other similar websites and then post a link.

Try to provide both a high-level overview of the problem (what goal you want to achieve) as well as a more detailed view of the problem (how are you trying to achieve your goal'. Often, there is a much easier way of getting things done that you may not know about.

Finally, make sure you have searched/read the relevant documentation (e.g. the FPC documentation and Lazarus wiki, see e.g. Lazarus Documentation. You should also search the forums: other people with may already have found solutions to similar problems. If you indicate you have already done a bit of homework, people will in general be much more willing to help.

For more tips about asking questions the smart way, read this: http://catb.org/esr/faqs/smart-questions.html

See also: How to use the forum

Version numbering

See the Version Numbering page for an explanation of the branching and version numbering of Lazarus.

Problems/issues with old Lazarus/FPC versions

Issues with old Lazarus/FPC versions and notes about upgrading are covered below.

Often, the best solution is to upgrade; please see the various Release Notes

Why is the linking so slow on Windows (Lazarus < 0.9.24)?

Light bulb  Note: This problem was fixed in FPC 2.2 and Lazarus 0.9.24. Please update your Lazarus if you can. For older versions read text below.

Generally speaking, compilation on Windows takes more time then other platforms because the GNU Linker utilized by Free Pascal is slow on this platform. This problem only affects Windows, and is only bad on relatively old computers (less then 1Ghz) and computers with little RAM (128MB or less).

Also, if you smartlink LCL the linking will be much slower. A study about this is located here: File size and smartlinking

Starting from FPC 2.2, an internal linker is used which decreases the linking time dramatically.

Old Lazarus does not support Windows-style resources; converting lrs resources

Older versions of FPC (and Lazarus based on it) don't support Windows (.rc/.res) resources, but only LRS files (Lazarus Resource files). See Lazarus Resources Since 0.9.30 Lazarus can use fpc resources. That means you can delete the lrs files for forms and replace the include directives {$I unit1.lrs} with {$R *.lfm}.

Antivirus

Excluding the Lazarus directory (and the directory/directories where your project/projects are) from on access virus scanning may help there.

See also