Sign in Join
Wiki copytemporary

Lazarus Faq/zh CN: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11这个 FAQ 是从 www.freepascal.org 的 FAQ 复制过来的,这样一来,这个 wiki 文档就更容易维护和扩充了。
22
33## 一般问题
44
55### 哪里有更多的 FAQ?
66
77可以看看 [官方站点](http://www.lazarus.freepascal.org)。那里也是另一个 FAQ。
88
99### 为什么编译成二进制文件会如此之大?
1010
1111编译产生的二进制文件如此之大的原因是,它包含了许多 **gdb** (GNU debugger,GNU 调试器)所需的信息。
1212
1313Free Pascal 编译器提供了一个命令行选项 **-Xs** 来移除这些调试信息。(注意,由于一个 bug,版本 2.0.2 及以前的编译器无法正确执行该选项。)
1414
1515您可以利用一个名为 **strip** 的程序来移除可执行文件中的所有调试符号 (debug symbols)。该程序位于 Lazarus 目录 `\lazarus\pp\bin\i386-win32` 下。要利用 **strip** 做到这一点,只需执行
1616
17-` `**`strip`**` `**`--strip-all`**` `*`exepath`*
17+```text
18+ strip --strip-all exepath
19+```
1820
1921其中 *`exepath`* 是您希望处理的可执行文件的路径名。
2022
2123如果您还希望让您的程序变得更小,不妨使用 [**UPX**](http://upx.sourceforge.net/)。**UPX** 是一个优秀的 EXE 压缩程序。由于使用了就地解压(in-place decompression)技术,它不会产生额外的内存开销。并且它的解压速度非常快(在 Pentium 133 上约为 10 MB/秒)。
2224
2325要使用 **UPX**,只需执行
2426
25-` `**`upx`**` `*`exepath`*
27+```text
28+ upx exepath
29+```
2630
2731其中 *`exepath`* 是您希望处理的可执行文件的路径名。
2832
2933一个简单的 GUI Lazarus 程序在使用过 **strip** 和 **UPX** 後,压缩效果为:
3034
3135- 在 Linux 上,约 700 KB;
3236- 在 Windows 上,约 420 KB。
3337
3438请注意 **UPX** 有时并非只会带来好处。要了解使用 *UPX* 可能带来的坏处,请参阅 [[Size Matters]]。
3539
3640另外值得注意的是,用 Lazarus 创建的程序——即使是十分简单的 Hello World 程序——也已经包含了大量重要的功能,包括
3741
3842- XML 处理库;
3943- 图像处理库,用于 PNG,XPM,BMP 和 ICO 格式;
4044- Lazarus 组件库中的几乎所有组件;
4145- 全部 Free Pascal 运行库。
4246
4347因此,虽然您的程序可能显得很大,但**它已经包含了一个真实世界中的非平凡 (non-trivial) 应用程序所需要的全部。**也因此,虽然用 Lazarus 创建的应用程序可能在一开始显得很大,但是,**随着程序复杂度的增加,其大小的增长速度却很慢。**这是由 Free Pascal 编译器和 Lazarus 窗体的工作原理决定的。
4448
4549与许多其他语言相比——例如——一个典型的 C++ 程序最初可能很小,但当您向其中加入各种功能时,其大小可能按指数级增长。
4650
4751![](/wiki-images/d/de/Lazarus_vs_cpp.png)
4852
4953### 为什么在 Windows 上的连接 (linking) 速度如此缓慢?(已解决)
5054
5155**该问题已在 Free Pascal 2.2 和 Lazarus 0.9.24 中得到解决。**请更新您的 Lazarus。如果您仍需使用旧版本,请继续阅读。
5256
5357一般地,在 Windows 上的编译过程比在其他平台上所需的时间长。而此问题的产生是由于 Free Pascal 所使用的 GNU 连接器 (GNU Linker)在 Windows 上运行缓慢。该问题影响的平台只有 Windows,并且也仅在配置相对较低的计算机(例如一台 CPU 频率 1 GHz,内存小于 128 MB 的计算机)上比较明显。
5458
5559并且,在这种情况下,如果您使用了智能连接 (Smart Linking) 选项连接 LCL,那么连接过程会更加缓慢。有关这一问题的研究,请参阅 [[File size and smartlinking]]。
5660
5761在 Free Pascal 2.2 中,开发人员实现了一个内部连接器。该连接器大大减少了连接所需的时间。
5862
5963### 我需要 ppc386.cfg 或 fpc.cfg 吗?
6064
6165您只需要 `fpc.cfg`。利用该文件,编译器可以了解库 (libraries) 的位置。
6266
6367### How do I compile lazarus?
6468
6569Do something like this:
6670
67-`$ cd lazarus`\
68-`$ make clean all`
71+```text
72+$ cd lazarus
73+$ make clean all
74+```
6975
7076### 我怎样在基于LCL的基础上建立其它项目
7177
7278If you can't use the IDE to build your applications, use lazbuild. This is a command line version of the IDE to build lazarus projects and packages. If you want to build LCL applications without the IDE and without the lazbuild, add the following lines to the end of your *fpc.cfg*
7379
74-`  # searchpath for other toolkits (Linux)`\
75-`  -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/{YourToolKit}`
80+```text
81+ # searchpath for other toolkits (Linux)
82+ -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/{YourToolKit}
83+```
7684
77-`  # searchpath for other toolkits (Windows)`\
78-` -Fu/{YourLazarusDirectory}/components/units/{YourToolKit}`
85+```text
86+ # searchpath for other toolkits (Windows)
87+ -Fu/{YourLazarusDirectory}/components/units/{YourToolKit}
88+```
7989
8090
8191Where {YourToolKit} may be *gtk2*, *gnome*, *qt* or *win32* and run:
8292
8393
8494ppc386 your.project.pp
8595
8696**Hint:** Don't forget to install the development packages for your toolkit otherwise you might a receive something like: [[Linker message: cannot find -l]].
8797
8898### fpc都包括哪些版本?
8999
901002.0.4 for MacOSX and 2.2.0 for all other systems. Warning: The 2.2.0 has a bug under MacOSX with case sensitive filenames. You can also use the svn version of fpc 2.2.1 and 2.3.x. 2.0.4版苹果和2.2.0所有其它的系统。 注意2.2.0在苹果平台有一个BUG。(译者注:细节自己看吧!)
91101
92102### 我不能编译 Lazarus
93103
941041. 检查编译器版本是否正确
951052. 检查(fpc)库文件版本是否相同
961063. 检查是否存在fpc.cfg,删除旧的ppc386.cfg文件
971074. 也检查一下系统要求的FAQ
98108
99109### 当我尝试编译一个项目,有一个错误
100110
101111#### "Cannot find Unit interfaces". How can I solve this?
102112
103113It means the compiler can not find the file 'interfaces.ppu' **or** it means it found one, but it is wrong or outdated.
104114
105115This 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.
106116
107117Make sure, it is only there. If you have multiple versions of interfaces.ppu, then you 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.
108118
109119If you selected a different widgetset than you used to build lazarus, you need to build the LCL for this widgetset.
110120
111121If 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
112122
113123- 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.
114124- 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!!
115125- 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.
116126
117127### 当我尝试在lazarus下编译delphi项目时,有一个错误
118128
119129#### at the line :{\$R *.DFM} How can I solve this problem ?
120130
121131Lazarus (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:
122132
123133- 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.
124134- Create a file with lazres (in lazarus/tools) lazres yourform.lrs yourform.lfm
125135- Add the following initialization section to
126136
127-`     initialization`\
128-`     {$I yourform.lrs}`
137+```text
138+ initialization
139+ {$I yourform.lrs}
140+```
129141
130142Please keep in mind that not all properties in the dfm are supported yet by lazarus, so you might get a crash.
131143
132144#### 'Identifier not found LazarusResources'.
133145
134146When 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.
135147
136148### 当访问对像事件,例如一个按钮的onclick事件,获得下列错误 ERROR unit not found: stdCtrls (错误的单元没有发现,stdCtrls)
137149
138150Make sure, in the Project -\> Project Inspector, that your project depends on the package 'LCL' and that you have installed the FPC sources.
139151
140152Lazarus 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.
141153
142154The FPC source path can be set via: Environment -\> Environment Options -\> Files -\> FPC source directory
143155
144156### 怎样将一个小文件嵌入到可执行文件中, 外部需要一个独立的文件? 怎样嵌入一个资源?
145157
146158例子:(译者注:该例子嵌入一个声音WAV资源)
147159
148-`/your/lazarus/path/tools/lazres sound.lrs sound1.wav sound2.wav ...`
160+```text
161+/your/lazarus/path/tools/lazres sound.lrs sound1.wav sound2.wav ...
162+```
149163
150164will create sound.lrs from sound1.wav and sound2.wav.
151165
152166Then include it *behind* the form lrs file:
153167
154-`...`\
155-`initialization`\
156-`{$i unit1.lrs} // this is main resource file (first)`\
157-`{$i sound.lrs} // user defined resource file`\
168+``` pascal
169+...
170+initialization
171+{$i unit1.lrs} // this is main resource file (first)
172+{$i sound.lrs} // user defined resource file
158173
159-`end.`
174+end.
175+```
160176
161177In your program you can then use:
162178
163-`Sound1AsString:=LazarusResources.Find('sound1').Value;`
179+``` pascal
180+Sound1AsString:=LazarusResources.Find('sound1').Value;
181+```
164182
165183### 我怎样能看到调试输出?
166184
167185The LCL has in the LCLProc procedure to write debug output:
168186
169187- **DebugLn:** works about the same as WriteLn, but accepts only strings.
170188- **DbgOut:** works about the same as Write, but accepts only strings.
171189
172190In 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.
173191
174192Debug 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\>.
175193
176194If 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 such an environment variable exists, it uses that as file to write debug output to. Example: if you do:
177195
178-`set lazarus_debuglog=c:\lazarus\debug.txt`
196+```text
197+set lazarus_debuglog=c:\lazarus\debug.txt
198+```
179199
180200debug output will be written to c:\lazarus\debug.txt.
181201
182202Since this is implemented in lclproc, every application using lclproc, can use this output facility.
183203
184204Debuging Lazarus
185205Most usefull for windows: If you want output on a console, add {\$APPTYPE console} to lazarus.pp ; Then rebuild Lazarus.
186206
187207### Lazarus 的各种各样的文件扩展名有什么意义?
188208
189209The [[Lazarus Tutorial|Lazarus Tutorial#The Lazarus files]] explains some extensions by an example. Here is a brief list:
190210
191211`*.lpi`
192212Lazarus Project Information file (stored in XML; contains project-specific settings)
193213
194214`*.lpr`
195215Lazarus Program file; contains Pascal source of main program
196216
197217`*.lfm`
198218Lazarus 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 `*.pas` file)
199219
200220`*.pas` or `*.pp`
201221Unit with Pascal code (typically for a form stored in a corresponding `*.lfm` file)
202222
203223`*.lrs`
204224Lazarus Resource file (this is a generated file; not to be confused with a Windows resource file).
205225
206226This file can be created with lazres tool (in directory Lazarus/Tools) using commandline: lazres myfile.lrs myfile.lfm
207227
208228`*.ppu`
209229Compiled unit
210230
211231`*.lpk`
212232Lazarus package information file. (stored in XML; contains package-specific settings)
213233
214234### I have fixed/improved lazarus. How can I add my changes to the official lazarus source?
215235
216236Create a patch and send it to the developers. For details see [[Creating A Patch]].
217237
218238### 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?
219239
220240The 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.
221241
222-`var`\
223-`  MyTextFile: TextFile;`\
224-`  MyText: System.Text;`
242+``` pascal
243+var
244+ MyTextFile: TextFile;
245+ MyText: System.Text;
246+```
225247
226248A 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*.
227249
228250### I get an error when using Printer.BeginDoc
229251
230252The unit Printers must be added to the uses section.
231253
232254The Printer4Lazarus package must be added to your project requirement in the IDE under: Project\|Project Inspector\|Add\|New Requirement\|Package Name:
233255
234256If 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: \[lazarus installed directory\]\components\printers
235257
236258If you used the default installation directories \[lazarus installed directory\] is:
237259
238260- Windows: c:\lazarus
239261- Linux: /usr/lib/lazarus
240262
241263The same solution also applies to the exception you can get when referencing Printer.Printers
242264
243265### Why are TForm.ClientWidth/ClientHeight the same as TForm.Width/Height
244266
245267The 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 endless.
246268
247269Eventually when there is a reliable way to get the size and position of a window with frame on all platforms, then it will be changed. To keep compatibility with older LCL forms, a version number and some extra methods will be added.
248270
249271### I created a Patch to dock the IDE Messages form on the "Source Code Editor" form (at bottom)
250272
251273Such 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 ... or not at all. For instance:
252274
253275 +-------------------++--+
254276 |menu || |
255277 +-------------------+| |
256278 +--++---------------+| |
257279 |PI|| Source Editor ||CE|
258280 +--+| || |
259281 +--+| || |
260282 | |+---------------++--+
261283 |OI|+-------------------+
262284 | ||messages |
263285 +--++-------------------+
264286
265287The 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.
266288
267289### How can I become a developer lazarus and access management in the SVN and bug-tracker?
268290
269291First of all: you must learn about Lazarus, to prove their knowledge and skill. Start to reading the [wiki articles](http://wiki.lazarus.freepascal.org/Lazarus_Documentation), read the Lazarus source code, giving a look at the [Lazarus Bug-Tracker](http://www.lazarus.freepascal.org/mantis), fix some bugs, and if you think you are ready, contact the developers on the [mailing list](http://www.mail-archive.com/lazarus@miraclec.com).
270292
271293## Where is ... defined
272294
273295### Virtual key constants
274296
275297Virtual key constants are defined in LCLType. Add LCLtype to your uses.
276298
277299## 使用 IDE
278300
279301### How can I use "identifier completion"?
280302
281303You 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.
282304
283305## Linux
284306
285307### How can I debug on Linux without the IDE?
286308
287309First 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:
288310
289-` $ make clean; make OPT=-dDEBUG`\
290-` $ ddd lazarus`
311+```text
312+ $ make clean; make OPT=-dDEBUG
313+ $ ddd lazarus
314+```
291315
292316Be warned however, that ddd is not as comfortable as e.g. the Lazarus debugger. 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.
293317
294318### I can debug now but ddd does not find my sources or complains that they contain no code. Whats that?
295319
296320This is a path-related problem with either gdb or ddd. You can aviod this by
297321
298322- 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.
299323- In ddd goto \[Edit\] \[gdb-settings\] and set the search-path
300324- Create a \$(HOME)/.gdbinit file like:
301325
302-`     directory /your/path/to/lazarus`\
303-`     directory /your/path/to/lazarus/lcl`\
304-`     directory /your/path/to/lazarus/lcl/include`
326+```text
327+ directory /your/path/to/lazarus
328+ directory /your/path/to/lazarus/lcl
329+ directory /your/path/to/lazarus/lcl/include
330+```
305331
306332### I receive an error during the linking that states /usr/bin/ld can't find -l\<some lib\>
307333
308334**Package Based Distributions**
309335You 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).
310336
311337**Source Based Distributions and Manual Compilation (LFS)**
312338Make 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).
313339
314340**FreeBSD**
315341As 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:
316342
317-`[]# cd /usr/local/lib && ln -s libglib-12.so libglib12.so`\
318-`[]# cd /usr/X11R6/lib && ln -s libgtk-12.so libgtk12.so`\
319-`[]# cd /usr/X11R6/lib && ln -s libgdk-12.so libgdk12.so`
343+```text
344+[]# cd /usr/local/lib && ln -s libglib-12.so libglib12.so
345+[]# cd /usr/X11R6/lib && ln -s libgtk-12.so libgtk12.so
346+[]# cd /usr/X11R6/lib && ln -s libgdk-12.so libgdk12.so
347+```
320348
321349**NetBSD**
322350As source based distro's, and also make sure you have -Fl/usr/pkg/lib in your fpc.cfg and/or Lazarus library path
323351
324352### How can I convert a kylix 2 project into a lazarus project?
325353
326354Nearly the same way as converting a Kylix project into a Delphi/VCL project.
327355
328356The LCL (Lazarus Component Library) tries to be compatible to Delphis VCL. Kylix CLX tries to be QT compatible. Here are some general hints:
329357
330358- Rename all used CLX Q-units like QForms, QControls, QGraphics, ... into their VCL counterparts: Forms, Controls, Graphics, ...
331359- Add LResources to the uses section of every form source
332360- Rename or copy all .xfm files to .lfm files.
333361- Rename or copy .dpr file to .lpr file.
334362- Add "Interfaces" to the uses section in the .lpr file.
335363- Remove {\$R *.res} directive
336364- Remove {\$R *.xfm} directive
337365- Add {\$mode objfpc}{\$H+} or {\$mode delphi}{\$H+} directive to .pas and .lpr files
338366- Add an initialization section to the end of each form source and add an include directive for the .lrs file (lazarus resource file):
339367
340-` initialization`\
341-`   {$I unit1.lrs}`
368+```text
369+ initialization
370+ {$I unit1.lrs}
371+```
342372
343373
344374The .lrs files can be created via the lazres tool in: (lazarusdir)/tools/lazres.
345375
346376For example: ./lazres unit1.lrs unit1.lfm
347377
348378- Fix the differences. The LCL does not yet support every property of the VCL and the CLX is not fully VCL compatible.
349379
350380- To make it more platform independant, 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 OS X, FreeBSD and Linux/x86_64)
351381
352382### When compiling lazarus the compiler can not find a unit. e.g.: gtkint.pp(17,16) Fatal: Can't find unit GLIB
353383
3543841\. Check a clean rebuild: do a 'make clean all'
355385
3563862\. Check if the compiler has the correct version (2.0.4 or higher)
357387
3583883\. 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.
359389
360390
361391**Hint:** You can see which config file is used with 'ppc386 -vt bogus'
362392
363393Remove any ppc386.cfg as it is really obsolete.
364394
3653954\. Check if the config file (/etc/fpc.cfg) contains the right paths to your fpc libs. There must be three lines like this:
366396
367-`   -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget`\
368-`   -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl`\
369-`   -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*`
397+```text
398+ -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
399+ -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl
400+ -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
401+```
370402
371403
372404The first part of these paths (/usr/lib/fpc) depends on your system. On some systems this can be for example /usr/local/lib/fpc/... .
373405
374406**Hint:** You can see your searchpaths with 'ppc386 -vt bogus'
375407
3764085\. Check that the config file (/etc/fpc.cfg) does not contain search paths to the lcl source files (.pp, .pas):
377409
378-` forbidden: -Fu(lazarus_source_directory)/lcl`\
379-` forbidden: -Fu(lazarus_source_directory)/lcl/interfaces/gtk`
410+```text
411+ forbidden: -Fu(lazarus_source_directory)/lcl
412+ forbidden: -Fu(lazarus_source_directory)/lcl/interfaces/gtk
413+```
380414
381415
382416If 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:
383417
384-` -Fu(lazarus_source_directory)/lcl/units/$fpctarget`\
385-` -Fu(lazarus_source_directory)/lcl/units/$fpctarget/gtk`
418+```text
419+ -Fu(lazarus_source_directory)/lcl/units/$fpctarget
420+ -Fu(lazarus_source_directory)/lcl/units/$fpctarget/gtk
421+```
386422
3874236\. 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.
388424
3894257\. 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.
390426
3914278\. If you are still not succeeded try to use samplecfg script as follows:
392428
393429*\#* cd /usr/lib/fpc/*version*/
394430
395431*\#* sudo ./samplecfg /usr/lib/fpc/*\\\$version* /etc
396432
397433Note! 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.
398434
399435### I have installed the binary version, but when compiling a simple project, lazarus gives: Fatal: Can't find unit CONTROLS
400436
401437Probably 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:
402438
403-` $ bash`\
404-` $ svn checkout `[`http://svn.freepascal.org/svn/lazarus/trunk`](http://svn.freepascal.org/svn/lazarus/trunk)` lazarus`\
405-` $ cd lazarus`\
406-` $ make clean all`
439+```text
440+ $ bash
441+ $ svn checkout http://svn.freepascal.org/svn/lazarus/trunk lazarus
442+ $ cd lazarus
443+ $ make clean all
444+```
407445
408446Make sure that lazarus get the new source directory: Environment-\>General Options-\>Files-\>Lazarus Directory Top
409447
410448### Lazarus compiles, but linking fails with: libgdk-pixbuf not found
411449
412450Install the gdk-pixbuf library for gtk1.x:
413451
414452Where to find the gdk-pixbuf library:
415453
416454RPMs: <http://rpmfind.net/linux/rpm2html/search.php?query=gdk-pixbuf&submit=Search+>...&system=&arch=
417455
418456Debian packages: libgdk-pixbuf-dev
419457
420458Sources: <ftp://ftp.gnome.org/pub/gnome/unstable/sources/gdk-pixbuf/>
421459
422460### I have SuSE and I get /usr/bin/ld: cannot find -lgtk Error: Error while linking
423461
424462SuSE 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).
425463
426464### Lazarus crashes with runtime error 211 after I installed a component
427465
428466After I installed a component, Lazarus crashes with the following message:
429467
430-`Threading has been used before cthreads was initialized.`\
431-`Make cthreads one of the first units in your uses clause.`\
432-`Runtime error 211 at $0066E188`
468+``` pascal
469+Threading has been used before cthreads was initialized.
470+Make cthreads one of the first units in your uses clause.
471+Runtime error 211 at $0066E188
472+```
433473
434474How can I fix this?
435475
436476Your 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:
437477
4384781\) 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.
439479
4404802\) In order to avoid modifying package, a 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.
441481
442482*Hint:* Maybe your old (non-crashing) lazarus executable is stored as lazarus.old in the same directory as the crashing lazarus executable.
443483
444484See also [[Multithreaded Application Tutorial|Multithreaded_Application_Tutorial#Units_needed_for_a_multithreaded_application]]
445485
446486### When I run a program with threads I get runtime error 232
447487
448488The complete error message is:
449489
450-`This binary has no thread support compiled in.`\
451-`Recompile the application with a thread-driver in the program uses`\
452-`clause before other units using thread.`\
453-`Runtime error 232`
490+``` pascal
491+This binary has no thread support compiled in.
492+Recompile the application with a thread-driver in the program uses
493+clause before other units using thread.
494+Runtime error 232
495+```
454496
455497**Solution**: Add cthreads as first unit to the uses clause of your main program, usually the .lpr-file.
456498
457499### I have Ubuntu Breezy and my fonts in Lazarus IDE look too big
458500
459501If 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:
460502
461503 style "default-text" {
462504 fontset = "-*-arial-medium-r-normal--*-100-*-*-*-*-iso8859-1,\
463505 -*-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
464506 }
465507
466508 class "GtkWidget" style "default-text"
467509
468510If this is not enough try and create also a .gtkrc symlink to .gtkrc.mine . It worked in this way under Xubuntu 7.10.
469511
470512### How can my gtk programs use custom rc files?
471513
472514Option a) Name the rc file *yourprogram.gtkrc* and put it in the same directory where the executable is.
473515
474516Option b) Use unit *GtkInt* and call *GTKWidgetSet.SetRCFilename('your_preferred_rc_file');* Best done before *Application.Initialize* in the .lpr file with *{\$IFDEF LCLGtk}*.
475517
476518### I have Ubuntu and I cannot compile for Gtk2 due to missing libraries
477519
478520Ubuntu 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:
479521
480522 cd /usr/lib
481523 sudo ln -s libgdk-x11-2.0.so.0 libgtk-x11-2.0.so
482524
483525Make sure that the \[whatever\].so symbolic links are created and point to the actual libraries.
484526
485527### How can I compile a program for Gtk2?
486528
487529At the moment, the Gtk2 compiled IDE is a little unstable, but you can compile software for Gtk2 using the Gtk1 IDE.
488530
489531To 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.
490532
491533Now click Ok and go to the menu "Tools"-\>"Build Lazarus"
492534
493535Now you can compile your software with Gtk2 going on the Compiler options and changing the widgetset to Gtk2.
494536
495537### I get this message: "\[WARNING\] ** Multibyte character encodings (like UTF8) are not supported at the moment."
496538
497539Since revision 10535 (0.9.21) this message doesn't exist anymore. 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.
498540
499541(original text for older versions of lazarus)\
500542This 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.
501543
502544To work around this, just change your locale to a non utf-8 before executing the program on the command line, like this:
503545
504546 export LC_CTYPE="pt_BR"
505547 export LANG="pt_BR"
506548 export LANGUAGE="pt_BR"
507549 ./lazarus
508550
509551Substitute pt_BR with the locale for your country. You can create a script to automate this.
510552
511553## Windows
512554
513555### 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.
514556
515557In the compiler dir exists an OS2 scriptfile named make.cmd. NT sees this also as a script file, so remove it since on NT we don't need it.
516558
517559### When I cycle the compiler, I get: make\[3\]: ./ppc1.exe: Command not found
518560
519561I don't know why but somehow make has lost its path. Try to cycle with a basedir set like: make cycle BASEDIR=your_fpc_source_dir_herecompiler
520562
521563### When I try to make Lazarus I get:
522564
523565#### make.exe: * * * interfaces: No such file or directory (ENOENT). Stop.make.exe: * * * \[interfaces_all\] Error 2
524566
525567You need to upgrade your make.
526568
527569#### makefile:27: *** You need the GNU utils package to use this Makefile. Stop.
528570
529571Make sure you didn't install FPC in a path with spaces in the name. The Makefile doesn't support it.
530572
531573### How can I give my program an XP look like lazarus has?
532574
533575If you have a myprogram.exe then create a file which called myprogram.exe.manifest and copy-paste this to the file:
534576
535-`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`\
536-`<assembly xmlns="`[`urn:schemas-microsoft-com:asm.v1`](urn:schemas-microsoft-com:asm.v1)`" manifestVersion="1.0">`\
537-`<assemblyIdentity processorArchitecture="*" version="1.0.0.0" type="win32" name="myprogram"/>`\
538-`<description>programom</description>`\
539-`<dependency>`\
540-`  <dependentAssembly>`\
541-`   <assemblyIdentity`\
542-`     type="win32"`\
543-`     name="Microsoft.Windows.Common-Controls"`\
544-`     version="6.0.0.0"`\
545-`     publicKeyToken="6595b64144ccf1df"`\
546-`     language="*"`\
547-`     processorArchitecture="*" />`\
548-`  </dependentAssembly>`\
549-`  </dependency>`\
550-`</assembly>`
577+``` pascal
578+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
579+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
580+<assemblyIdentity processorArchitecture="*" version="1.0.0.0" type="win32" name="myprogram"/>
581+<description>programom</description>
582+<dependency>
583+ <dependentAssembly>
584+ <assemblyIdentity
585+ type="win32"
586+ name="Microsoft.Windows.Common-Controls"
587+ version="6.0.0.0"
588+ publicKeyToken="6595b64144ccf1df"
589+ language="*"
590+ processorArchitecture="*" />
591+ </dependentAssembly>
592+ </dependency>
593+</assembly>
594+```
551595
552596Voila! XP looks.
553597
554598### When I run Windows program created in Lazarus it starts with a DOS window
555599
556600Specify 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.
557601
558602## Mac OS X
559603
560604### Why does compiling a project fail with 'unknown section attribute: no_dead_strip'?
561605
562606Dead code stripping is not supported by the assembler and linker before Mac OS X 10.4.0. Disable the compiler options
563607
564608- Code \> Unit style \> Smart linkable (-CX)
565609- and Linking \> Link Style \> Link smart (-XX)
566610
567611--Comment: I don't believe this is tied to a particular version of OS X, but rather to the version of Xcode installed. See this [link](http://developer.apple.com/releasenotes/DeveloperTools/RN-CompilerTools/index.html#//apple_ref/doc/uid/TP40001264-DontLinkElementID_12). On my PowerPC 10.4.11 system with Xcode 2.4.1 and FPC 2.2.0, both -CX and -XX work, but the code savings appear to be negligible.
568612
569613## 许可
570614
571615### 我能用 Lazarus 开发商业应用程序吗?
572616
573617可以。LCL 的许可方式是带例外的 LGPL,该例外允许您将其静态连接到您的应用程序中,而无需发布其代码。但是,任何对 LCL 本身的修改或增强都必须以代码形式发布。Lazarus 即 IDE 本身,是以 GPL 许可的。
574618
575619### 为什么有些组件不能用于商业应用程序?
576620
577621Lazarus 带有附加组件,它们由第三方开发,也有着不同的许可方式。如果您需要使用它们,请参阅他们各自的许可文件。
578622
579623多数第三方组件都位于 `\lazarus\components` 目录中。
580624
581625### How do I know if a Component is part of the LCL ?
582626
583627All LCL units are in the directory "lcl". A List of units belonging to the LCL can be found here <http://lazarus-ccr.sourceforge.net/docs/lcl/> . If you code uses units not listed on this page, you may have used a component that is not part of the LCL.
584628
585629### Can I make commercial plug-ins for Lazarus ?
586630
587631Yes, 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.
588632
589633## Contributors and Comments
590634
591635This page has been converted from the epikwiki [version](http://lazarus-ccr.sourceforge.net/index.php?wiki=LazarusFaq).
592636
593637---
594638*From the Free Pascal wiki, page "Lazarus Faq/zh CN", as it stood on 2015-06-06 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
595639Category: FAQs/zh CN
596640Category: Lazarus/zh CN

Back to history