libc library: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | Not to be confused with [[libc unit|libc Kylix compatibility unit]] | |
| 2 | 2 | ||
| 3 | 3 | ## Linking | |
| 4 | 4 | ||
| 5 | 5 | <http://forum.lazarus.freepascal.org/index.php/topic,44784.msg315189.html#new> | |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | **Question:** | |
| 9 | 9 | ||
| 10 | 10 | According to <https://www.freepascal.org/docs-html/current/prog/progsu46.html> | |
| 11 | 11 | ||
| 12 | 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 | 13 | ||
| 14 | 14 | The same can be obtained by removing the linklib directive in the above unit, and specify -k-lc on the command line: | |
| 15 | 15 | ||
| 16 | - | ||
| 16 | + | ```text | |
| 17 | + | ppc386 -k-lc foo.pp | |
| 18 | + | ``` | |
| 17 | 19 | ||
| 18 | 20 | This does not give me the same results. The program appears to link correctly, but the resulting binary refuses to run. | |
| 19 | 21 | ||
| 20 | 22 | ||
| 21 | 23 | **Answer:** | |
| 22 | 24 | ||
| 23 | 25 | {\$linklib c} is indeed the only correct way, and this is an error in the manual. | |
| 24 | 26 | ||
| 25 | 27 | -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 | 28 | ||
| 27 | 29 | {\$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 | 30 | ||
| 29 | 31 | ## See Also | |
| 30 | 32 | ||
| 31 | 33 | - <https://en.wikipedia.org/wiki/C_standard_library> | |
| 32 | 34 | ||
| 33 | 35 | --- | |
| 34 | 36 | *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 | 37 | Category: FPC |
