libc library: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: libc library
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Not to be confused with [[libc unit|libc Kylix compatibility unit]] | |
| 2 | + | ||
| 3 | + | ## Linking | |
| 4 | + | ||
| 5 | + | <http://forum.lazarus.freepascal.org/index.php/topic,44784.msg315189.html#new> | |
| 6 | + | ||
| 7 | + | ||
| 8 | + | **Question:** | |
| 9 | + | ||
| 10 | + | According to <https://www.freepascal.org/docs-html/current/prog/progsu46.html> | |
| 11 | + | ||
| 12 | + | I have to use {\$LINKLIB c} in my Pascal source file, this works as expected, the binary links correcly and the resulting program runs as expected, however the documentation mentions Quote | |
| 13 | + | ||
| 14 | + | The same can be obtained by removing the linklib directive in the above unit, and specify -k-lc on the command line: | |
| 15 | + | ||
| 16 | + | `ppc386 -k-lc foo.pp ` | |
| 17 | + | ||
| 18 | + | This does not give me the same results. The program appears to link correctly, but the resulting binary refuses to run. | |
| 19 | + | ||
| 20 | + | ||
| 21 | + | **Answer:** | |
| 22 | + | ||
| 23 | + | {\$linklib c} is indeed the only correct way, and this is an error in the manual. | |
| 24 | + | ||
| 25 | + | -k-lc just passes the "-lc" command line parameter to the linker, without the compiler having any clue about what it does. This means that the C library will be linked, but nothing else gets changed. | |
| 26 | + | ||
| 27 | + | {\$linklib c} additionally also makes the compiler replace the initialisation code of the library (or program) with a version that initialises the C library (since by default FPC programs and libraries do not use the C library on most platforms, it cannot contain any code to initialise it either). Without this initialisation, the C library indeed won't work correctly. | |
| 28 | + | ||
| 29 | + | ## See Also | |
| 30 | + | ||
| 31 | + | - <https://en.wikipedia.org/wiki/C_standard_library> | |
| 32 | + | ||
| 33 | + | --- | |
| 34 | + | *From the Free Pascal wiki, page "libc library", as it stood on 2019-03-28 after a change by Skalogryz, 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).* | |
| 35 | + | Category: FPC |
