faq.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. Frequently Asked Questions
  2. 1. What is Free Pascal (FPC)?
  3. Originally named FPK-Pascal, the Free Pascal compiler is a 32 bit
  4. Turbo Pascal compatible Pascal compiler for DOS, Linux, Win32,
  5. OS/2 and (based on an older version) the AmigaOS. More operating
  6. systems are in the works.
  7. The compiler is written in Pascal and is able to compile its own
  8. sources. The source files are included.
  9. Free Pascal is modest regarding its minimal system requirements
  10. (386-25 Mhz for the Intel version and ideally a 68020 processor
  11. for the Motorola version). At least 2 megabytes of RAM are
  12. required. To remake the compiler more than 16MB is recommended.
  13. Short history:
  14. + 6/1993: project start
  15. + 10/1993: first little programs work
  16. + 3/1995: the compiler compiles the own sources
  17. + 3/1996: released to the internet
  18. + 7/2000: 1.0 version
  19. 2. Which versions exist, and which one should I use?
  20. Compilers with an even last number are release versions(e.g.
  21. 0.99.8, 0.99.10, 0.99.12, 0.99.14 and 1.00)
  22. Compilers and packages with an odd last number are development
  23. versions (e.g. 0.99.9, 0.99.11, 0.99.13, 0.99.15 and 1.0.9).
  24. 0.99.5 is an exception to this rule, since 0.99.5 IS a release (a
  25. release prior to the introduction of this odd/even system)
  26. Letters behind the version number (0.99.12b, 0.99.5d) indicate
  27. release versions with some bugs and problems in the original
  28. release (respectively 0.99.12 and 0.99.5) fixed.
  29. Normally you would want to use a release. Releases are considered
  30. stable, and easier to support (the bugs, quirks and unintended
  31. "features" are well known after a period of time, and workarounds
  32. exist).
  33. Development snapshots (which are generated daily) reflect the
  34. current status of the compiler. Development versions probably have
  35. new features and larger bugs fixed since the last release, but
  36. might have some temporary stability drawbacks (which are usually
  37. fixed by the next day)
  38. Most support for development snapshots are basically the advise to
  39. upgrade to newer snapshot in which the bugs are hopefully fixed.
  40. Since version 0.99.8 the stability of the compiler steadily
  41. increased and development snapshots are often quite useful for
  42. certain categories of users. Ask in the maillists if it is worth
  43. the trouble in your case if you're not sure.
  44. The current release version is 1.00 for the OS/2, Linux, Windows
  45. and Dos (Go32V2) targets and 0.99.5d for the 680x0 based systems
  46. (Amiga and Atari ST)
  47. The current development snapshot version is 1.0.9.
  48. 3. Free Pascal and GNU Pascal - a comparison
  49. Aim:
  50. Free Pascal tries to implement a Borland compatible
  51. pascal compiler on as many platforms as possible. GNU
  52. Pascal tries to implement a portable pascal compiler
  53. based on POSIX.
  54. Version:
  55. Currently, Free Pascal is at version 1.00 for the Intel
  56. version and version 0.99.5d for the Motorola/Intel
  57. version. Version 0.99.5d differs from version 0.99.5 in
  58. that all run time library fixes have been applied, as
  59. well as all known code generation bugs. Version 1.00
  60. differs from version 0.99.5d in that all parser bugfixes
  61. have also been applied and also a lot of Delphi 2 and
  62. Delphi 3 extensions have been implemented. GNU Pascal is
  63. at version 2.8.1 (but this numbering is not really an
  64. indication, it follows the GNU C numbering, since it is a
  65. derivation of it)
  66. Operating systems:
  67. Free pascal runs on a limited number of systems : DOS,
  68. Win32, Linux, OS/2 and AmigaOS and is for the moment
  69. limited to the Intel and Motorola architectures. GNU
  70. Pascal runs basically on any system that can run GNU C.
  71. Sources:
  72. Free Pascal is entirely written in Pascal (about 4 Mb of
  73. source code), while GNU Pascal is written in C (it's an
  74. adaptation of the GNU C compiler: 2.8 Mb code + 8 MB of
  75. GNU C code)
  76. Language:
  77. Free Pascal supports the Borland Pascal dialect Borland,
  78. and implements the Delphi Object Pascal language. GNU
  79. Pascal supports ISO 7185, ISO 10206, (most of) Borland
  80. Pascal 7.0
  81. Extensions:
  82. Free Pascal implements function overloading and operator
  83. overloading. GNU Pascal implements operator overloading.
  84. License:
  85. Both compilers come under the GNU GPL.
  86. Author:
  87. Free Pascal was started by Florian Klaempfl, Germany
  88. ([email protected]), GNU Pascal was started by
  89. Jukka Virtanen, Finland ([email protected]).
  90. 4. Where can I get the compiler ?
  91. Free Pascal is available for download from all [46]official
  92. mirrors
  93. 5. What are the considerations in porting code to other processors?
  94. Because the compiler now supports processors other than the Intel,
  95. it is important to take a few precautions so that your code will
  96. execute correctly on all processors.
  97. + Limit your use of asm statements unless it is time critical
  98. code
  99. + Don't use the packed directive unless you know exactly what
  100. you are doing. Most processors require alignment of data, and
  101. using packed on objects,classes and records may break this
  102. requirement. If this is the case your code will simply crash
  103. on the target processors.
  104. + Clean up at the end of your program, i.e. close all files on
  105. exit, as some operating systems don't like it when some files
  106. are left opened.
  107. + Try not to rely on the endian of the specific machines when
  108. doing arithmetic operations. Furthermore, reading and writing
  109. of binary data to/from files will probably require byte swaps
  110. across different endian machines (swap is your friend in this
  111. case)
  112. + Try limiting your local variables in subroutines to 32K, as
  113. this is the limit of some processors, use dynamic allocation
  114. instead.
  115. + Try limiting the size of parameters passed to subroutines to
  116. 32K, as this is the limit of some processors, use const or
  117. var parameters instead.
  118. 6. I tried to compile my Delphi code with the Free Pascal Compiler,
  119. but it seems that it doesn't recognize Delphi style OOP.
  120. The compiler supports the Delphi OOP. Make sure you use the -S2 or
  121. -Sd switches (see the manuals for the meaning of these switches).
  122. 7. I have to write a program for homework. Can you help?
  123. No. Please, don't send us mail about homework, we are no teachers.
  124. The Free Pascal development team tries to give good support for
  125. the Free Pascal compiler and are trying to always reply to emails.
  126. If we get emails like this, this becomes harder and harder.
  127. 8. How can I build a unit?
  128. It works like in Turbo Pascal. The first keyword in the file must
  129. be UNIT (not case sensitive). The compiler will generate two
  130. files: XXX.PPU and XXX.O. The PPU file contains the interface
  131. information for the compiler and the O-file the machine code (an
  132. object file, whose precise structure depends on the assembler you
  133. used). To use this unit in another unit or program, you must
  134. include its name in the USES clause of your program.
  135. 9. Will Free Pascal support TV (Turbo Vision) in the future?
  136. A Turbo Vision port, called Free Vision, has progressed nicely
  137. lately. It's already very usable, we are even writing an IDE in
  138. it. Due to copyrights problem the FreeVision source code is not
  139. available at the moment. You can download the IDE from the
  140. [47]development page. and get an idea of the look and feel though.
  141. 10. How can I compile the system unit?
  142. To recompile the system unit, it is recommended to have GNU make
  143. installed. typing 'make' in the rtl source directory will then
  144. recompile all RTL units including the system unit. You may choose
  145. to descend into the directory of your OS (e.g. rtl/go32v2) and do
  146. a 'make' there.
  147. It is possible to do all this manually, but you need more detailed
  148. knowledge of the RTL tree structure for that.
  149. 11. I get an internal error 9999
  150. The latest versions of the Free Pascal Compiler come with an error
  151. handling routine which catches the segmentation fault and lets the
  152. compiler to exit gracefully. This is reported as an internal error
  153. 9999. Please try to reproduce the error and send [48]us a bug
  154. report.
  155. (For the curious, IE 9999 is not a specific bug. It is a safety
  156. measure which terminates if during compiling a certain condition
  157. is not met, which can be caused by several bugs. So if you report
  158. the bug, and get IE 9999 later in a different piece or part of
  159. sourcecode, it could be a completely different bug.)
  160. 12. How does function overloading work?
  161. function overloading is implemented, like in C++:
  162. procedure a(i : integer);
  163. begin
  164. end;
  165. procedure a(s : string);
  166. begin
  167. end;
  168. begin
  169. a('asdfdasf');
  170. a(1234);
  171. end.
  172. You must be careful. If one of your overloaded functions is in the
  173. interface part of your unit, then all overloaded functions must be
  174. in the interface part. If you leave one out, the compiler will
  175. complain with a 'This overloaded function can't be local' message.
  176. Overloaded functions must differ in their parameters, it's not
  177. enough if their return types are different.
  178. 13. How can I call C functions?
  179. C calling convention is implemented as follows: The compiler
  180. pushes the parameters from right to left, but the procedure has to
  181. clear the stack. For calling the C function strcmp declare the
  182. following:
  183. function strcmp(s1 : pchar;s2 : pchar) : integer;cdecl;external;
  184. Since 0.99.5, the older [C]; won't work!
  185. 14. When will Free Pascal use DJGPP 2.0 under DOS/Windows?
  186. As of version 0.99.0 Free Pascal uses DJGPP 2.0. DJGPP v1.2
  187. support has been removed since version FPC 0.99.8.
  188. 15. How can I use the graph unit with Free Pascal?
  189. Since 0.99.12, the graph unit is available both for Dos and Linux.
  190. Under Dos, it only supported VESA modes though. Since version
  191. 0.99.14, a new more system independant graph unit is included
  192. (although the only extra supported OS is Win32 and this is only
  193. rudimentary support) which also supports standard VGA.
  194. 16. Integrated Assembler syntax
  195. The default assembler syntax (AT&T style) is different from the
  196. one in Borland Pascal (Intel style).
  197. However, as of version 0.99.0, the compiler supports Intel style
  198. assembly syntax. See the documentation for more info on how to use
  199. different assembler styles.
  200. A description of the AT&T syntax can be found in the DJGPP FAQ
  201. [49]http://www.delorie.com/djgpp/v2faq/faq102.html#Syntax or in
  202. Brennan's Guide to Inline Assembly
  203. [50]http://www.rt66.com/%7Ebrennan/djgpp/djgpp asm.html. The
  204. documentation also contains a chapter where the difference between
  205. the Intel and AT&T style assembly is explained.
  206. Or you can use the convertor program at
  207. [51]http://rcs.urz.tu-dresden.de/schoenfu/zip/asmtrans.zip .
  208. 17. How can I access DOS memory / How can I do graphics programming?
  209. You can do like in TP, via absolute or mem[]. For larger memory
  210. blocks use the dosmemput/dosmemget routines in Go32 unit.
  211. 18. How can I run Free Pascal without a math coprocessor?
  212. On the Intel version the emulator is automatically loaded by the
  213. compiler if you add the following commands to your autoexec.bat:
  214. SET 387=N
  215. SET EMU386=C:\PP\BIN\GO32V2\WEMU387.DXE
  216. (don't forget to replace the C:\PP with the directory where you
  217. installed FPC)
  218. 19. How do I reserve more than 2 megabytes of RAM?
  219. By default Free Pascal allocates only 2MB of RAM for your
  220. application. If it just allocated all it could get, people running
  221. Windows would have problems as Windows would increase the swap
  222. file size to give the program more memory on and on, until the
  223. swap file drive would be full.
  224. You can specify the size of the heap with -Chxxxx. The default
  225. value is -Ch4000000. Try -Ch10000000, provided you got enough swap
  226. space.
  227. However, the heap size doesn't really matter anymore, since the
  228. Heap is able to grow: if you've used all the available heap space,
  229. the program will try to get more memory from the OS, so the heap
  230. is limited to the maximum amount of free memory provided by the
  231. OS.
  232. It is only handy if you know you will need at least a certain
  233. amount of memory. You can then specify this value using the -Ch
  234. parameter, so your program will allocate it at once on startup.
  235. This is slightly faster than growing the heap a number of times.
  236. 20. How can I access I/O ports?
  237. With versions before 0.99.10: if you're under DOS you can use the
  238. outport* and inport* procedures of the go32 unit.
  239. Since version 0.99.8, the Port array is supported like in TP, as
  240. long as you use the ports unit in your program (not available
  241. under Win32).
  242. 21. I'm using the Dos compiler under Windows 95
  243. There is a problem with the Dos compiler and Win 95 on computers
  244. with less than 16 MB. First set in the properties of the DOS box
  245. the DPMI memory size to max value. Now try to start a demo program
  246. in the DOS box, e.g. HELLO (starting takes some time). If this
  247. works you will be able to get the compiler to work by recompiling
  248. it with a smaller heap size, perhaps 2 or 4 MB (option -Chxxxx).
  249. 22. I'm using OS/2
  250. Problems have been reported that the GO32v2 compiler does not run
  251. on some OS/2 installations. You can use the native OS/2 compiler
  252. (strongly preferred solution) or maybe compile a GO32v1 compiler
  253. yourself. However, the GO32v2 version should generally work under
  254. OS/2 as well.
  255. 23. INSTALL.EXE of Dos version 0.99.10 reports "Load error: no DPMI"
  256. The file cwsdpmi.exe is missing in the main directory of the zip
  257. archive. The above message pops up if no other DPMI services are
  258. available. Such services are for example available in a Dos window
  259. of Windows. You can either extract that file from basego32.zip or
  260. download it from
  261. [52]http://www.brain.uni-freiburg.de/%7Eklaus/cwsdpmi.exe. Put it
  262. into the same directory as install.exe and run install again.
  263. 24. INSTALL.EXE of Dos version 0.99.10 does not run in Windows NT
  264. This is an incompatibility of the mouse driver. Use this new
  265. version of install.exe instead:
  266. [53]ftp://ftp.freepascal.org/pub/fpc/snapshot/install.exe
  267. 25. I want a new version NOW
  268. In the time between the release of new official versions, you can
  269. have a look at and test developer versions (so-called
  270. "snapshots"). Be warned though: this is work under progress, so in
  271. addition to old bugs fixed and new features added, this may also
  272. contain new bugs.
  273. Snapshots are generated automatically each night from the current
  274. source at that moment. Sometimes this may fail due to bigger
  275. changes not yet fully implemented. If your version doesn't work,
  276. try again one or two days later. You're advised not to download
  277. the GO32v1 version for Dos, since it's not supported any more.
  278. The latest snapshot can always be downloaded from the
  279. [54]development web page.
  280. To install a snapshot, extract the zip archive into the existing
  281. program directory of the last official version of Free Pascal
  282. (after making a backup of the original of course). You can also
  283. extract it into an empty directory and then move the files to the
  284. program directory, overwriting existing files. Make sure that you
  285. extract the ZIP archive such that the included directory structure
  286. remains intact. For example if you use PKUNZIP, use "pkunzip -d"
  287. instead of just "pkunzip". Note that snpashots also contain a new
  288. RTL which most likely can't be used with the previous release
  289. version, so backup your old RTL as well.
  290. 26. Where can I find a text mode IDE?
  291. The development of the IDE (integrated development environment) is
  292. not yet finished. However a working test version of the IDE is
  293. available as snapshot. It requires the latest compiler snapshot be
  294. installed on top of the current official version for your
  295. particular platform (1.00 for GO32v2 or Win32). So if you have not
  296. already done that, first install the latest official version (e.g.
  297. file dos100.zip or dos100full.zip, you find these in the
  298. [55]download section).
  299. Then get and extract the latest snapshot for your platform (e.g.
  300. snapshot.zip) into the directory containing the official version.
  301. Next, do the same with one of the IDE snapshots. For more details
  302. on where to find and how to install a snapshot, please see the
  303. previous FAQ item. For additional instructions for required IDE
  304. configuration please also read the next FAQ item.
  305. 27. How do I configure the Dos IDE?
  306. Once you have installed the IDE (see the previous FAQ item), it
  307. requires two configuration changes before it can compile. This is
  308. due to the fact that the IDE includes its own compiler; it does
  309. not use ppc386.exe and thus it also does not use the configuration
  310. in the file ppc386.cfg.
  311. Start fp.exe, select Target from the Compile menu and then check
  312. GO32v2. Next, choose Directories in the Otions menu and in the
  313. line "Unit directories" enter the path to your copy of the rtl
  314. directory, usually c:\pp\rtl\go32v2. If you have done everything
  315. correct and it still doesn't work, you may have grabbed a snapshot
  316. that has a bug; in this case try again one or two days later or
  317. ask for help on one of the [56]mailing lists.
  318. 28. Why are the generated binaries so big?
  319. There are several reasons and remedies for this:
  320. 1. If you are using 0.99.12: Due to some problems with the
  321. binary writer, 0.99.12 wasn't released with smartlinkable
  322. RTLs. Smartlinking causes only actually used procedures,
  323. functions and constants to be linked in.
  324. You can remedy this by using a development version and
  325. creating a smartlinking RTL. See the [57]make cycle faq or
  326. use a later release if available (0.99.14 and later do
  327. include a smartlinkable RTL). To turn on the generation of
  328. smartlinkable units, use the -Cx command line option when
  329. compiling your units. To turn on the linking of previously
  330. generated smarlinkable units, use the -XX (-XS in 0.99.12 and
  331. earlier) command line option when compiling a program.
  332. 2. Normally, all symbol information is included in the resulting
  333. program (for easier debugging). You can remove this by using
  334. the -Xs command line option when compiling your program (it
  335. won't do anything when compiling units)
  336. 3. You can use UPX to pack the .EXEs (just like e.g. pklite) for
  337. Dos (GO32v2) and Windows targets. Look [58]here for more
  338. info.
  339. 4. You can use LXLITE for packing EMX binaries, but you won't be
  340. able to run them under DOS (with extender) any more then. It
  341. might even not be possible to use them on lower OS/2 versions
  342. (like 2.x) depending on chosen type of compression. LXLITE
  343. can be found e.g. on [59]Hobbes, search for LXLITE.
  344. 5. Turn on optimalisations, both for supplied packages (RTL,
  345. API, FV, FCL) and for your own code, this will also decrease
  346. the code size.
  347. 29. Unit system, syslinux, sysos2 or syswin32 not found errors
  348. System (syslinux, sysos2 or syswin32, depending on platform) is
  349. Pascal's base unit which is implicitely used in all programs. This
  350. unit defines several standard procedures and structures, and must
  351. be found to be able to compile any pascal program by FPC.
  352. The location of the system.ppu and syslinux.o files are determined
  353. by the -Fu switch which can be specified commandline, but is
  354. usually in the ppc386.cfg (Win32: ppc386w.cfg) configuration file.
  355. If the compiler can't find this unit there are three possible
  356. causes:
  357. 1. The ppc386.cfg isn't in the same path as the compiler
  358. executable (go32v2, win32 and OS/2) or can't be found as
  359. "/etc/ppc386.cfg" or ".ppc386.cfg" in your homedirectory
  360. (Linux).
  361. 2. The ppc386.cfg doesn't contain the -Fu line, or a wrong one.
  362. See the [60]make cycle faq, especially the chapters about the
  363. ppc386.cfg and the directory structure.
  364. 3. The files ARE found but the wrong version or platform.
  365. Correct ppc386.cfg to point to the right versions or
  366. reinstall the right versions (this can happen if you try to
  367. use a [61]snapshot compiler while the -Fu statemnt in the
  368. used ppc386.cfg still points to the RTL that came with the
  369. official release compiler).
  370. A handy trick can be executing "ppc386 programname -vt", this
  371. shows where the compiler is currently looking for the system
  372. unit's files. You might want to pipe this through more (Dos, OS/2,
  373. Windows) or less (Linux), since it can generate more than one
  374. screen information:
  375. Dos, OS/2, Windows:
  376. ppc386 programname -vt |more
  377. Linux:
  378. ppc386 programname -vt |less
  379. 30. Known bugs
  380. Go to the [62]bugs page
  381. 31. How can I find where an error occurred using the addresses a
  382. crashed program prints?
  383. 1. Starting with version 1.00, the easiest possibility is to
  384. compile your program with -gl debugging option. This way unit
  385. LineInfo is automatically linked in, and the printout after a
  386. program crash then contains source line numbers in addition
  387. to addresses.
  388. 2. For older versions, or more comprehensive checking, compile
  389. the program with debugging information (use the -g command
  390. line option)
  391. 3. Load the program in the debugger (gdb(w) for 0.99.12b and
  392. earlier, gdbpas(w) for 0.99.14 and later) using
  393. gdb(pas)(w) --directory=<src dirs>; myprog.exe
  394. Notes:
  395. o Under Linux, don't add the ".exe" after myprog
  396. o "src dirs" is a list of directories containing the
  397. source code files of myprog and the units it uses
  398. seperated by semi-colons (";"). The current directory is
  399. automatically included.
  400. 4. Once inside the debugger, you can (optionally) set the
  401. command line options that will be passed to your program
  402. using the command "set args <;option1 option2 ...>"
  403. 5. To start the program, type "run" and press enter
  404. 6. After the program has crashed, the address of the instruction
  405. where the crash occurred will be shown. The debugger will try
  406. to display the source code line corresponding with this
  407. address. Note that this can be inside a procedure of the RTL,
  408. so the source may not always be available and most likely the
  409. RTL wasn't compiled with debugging information.
  410. 7. If you then type "bt" (BackTrace), the addreses in the call
  411. stack will be shown (the addresses of the procedures which
  412. were called before the program got to the current address).
  413. You can see which source code lines these present using the
  414. command
  415. info line *<address>
  416. For example:
  417. info line *0x05bd8