Sign in Join
Wiki copytemporary

libc library: what changed

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

OldNewLine
11Not to be confused with [[libc unit|libc Kylix compatibility unit]]
22
33## Linking
44
55<http://forum.lazarus.freepascal.org/index.php/topic,44784.msg315189.html#new>
66
77
88**Question:**
99
1010According to <https://www.freepascal.org/docs-html/current/prog/progsu46.html>
1111
1212I 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
1313
1414The same can be obtained by removing the linklib directive in the above unit, and specify -k-lc on the command line:
1515
16-`ppc386 -k-lc foo.pp `
16+```text
17+ppc386 -k-lc foo.pp
18+```
1719
1820This does not give me the same results. The program appears to link correctly, but the resulting binary refuses to run.
1921
2022
2123**Answer:**
2224
2325{\$linklib c} is indeed the only correct way, and this is an error in the manual.
2426
2527-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.
2628
2729{\$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.
2830
2931## See Also
3032
3133- <https://en.wikipedia.org/wiki/C_standard_library>
3234
3335---
3436*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).*
3537Category: FPC

Back to history