xref: /freebsd/share/man/man3/intro.3 (revision fd5aaf2ea0178b03aa93c35245053247e5d3840c)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)intro.3	8.1 (Berkeley) 6/5/93
29.Dd November 16, 2023
30.Dt INTRO 3
31.Os
32.Sh NAME
33.Nm intro
34.Nd introduction to the C libraries
35.Sh SYNOPSIS
36.Nm cc
37.Op Ar flags
38.Ar
39.Op Fl llibrary
40.Sh DESCRIPTION
41This section provides an overview of the C
42library functions, their error returns and other
43common definitions and concepts.
44Most of these functions are available from the C library,
45.Em libc .
46Other libraries, such as the math library,
47.Em libm ,
48must be indicated at compile time with the
49.Fl l
50option of the compiler.
51.Pp
52The various libraries (followed by the loader flag):
53.Bl -tag -width "libbluetooth"
54.It Em libbluetooth
55.Pq Fl l Ns Ar bluetooth
56The bluetooth library.
57See
58.Xr bluetooth 3 .
59.It Em libc
60.Pq Fl l Ns Ar c
61Standard C library functions.
62When using the C compiler
63.Xr cc 1 ,
64it is not necessary
65to supply the loader flag
66.Fl l Ns Ar c
67for these functions.
68There are several `libraries' or groups of functions included inside of
69.Em libc :
70.Bl -tag -width "XXXXXX"
71.It standard I/O routines
72see
73.Xr stdio 3
74.It database routines
75see
76.Xr db 3
77.It bit operators
78see
79.Xr bitstring 3
80.It string operators
81see
82.Xr string 3
83.It character tests and character operators
84.It storage allocation
85see
86.Xr mpool 3
87.It regular-expressions
88see
89.Xr regex 3
90.It remote procedure calls (RPC)
91see
92.Xr rpc 3
93.It time functions
94see
95.Xr time 3
96.It signal handling
97see
98.Xr signal 3
99.El
100.It Em libcalendar
101.Pq Fl l Ns Ar calendar
102The calendar arithmetic library.
103See
104.Xr calendar 3 .
105.It Em libcam
106.Pq Fl l Ns Ar cam
107The common access method user library.
108See
109.Xr cam 3 .
110.It Em libcrypt
111.Pq Fl l Ns Ar crypt
112The crypt library.
113See
114.Xr crypt 3 .
115.It Em libcurses
116.Pq Fl l Ns Ar curses Fl l Ns Ar termcap
117Terminal independent screen management routines
118for two dimensional non-bitmap display terminals.
119See
120.Xr ncurses 3 .
121.It Em libcuse
122.Pq Fl l Ns Ar cuse
123The userland character device library.
124See
125.Xr cuse 3 .
126.It Em libcompat
127.Pq Fl l Ns Ar compat
128Functions which are obsolete but are available for compatibility with
129.Bx 4.3 .
130In particular,
131a number of system call interfaces provided in previous releases of
132.Bx
133have been included for source code compatibility.
134Use of these routines should, for the most part, be avoided.
135The manual page entry for each compatibility routine
136indicates the proper interface to use.
137.It Em libdevinfo
138.Pq Fl l Ns Ar devinfo
139The Device and Resource Information Utility library.
140See
141.Xr devinfo 3 .
142.It Em libdevstat
143.Pq Fl l Ns Ar devstat
144The Device Statistics library.
145See
146.Xr devstat 3 .
147.It Em libdwarf
148.Pq Fl l Ns Ar dwarf
149The DWARF access library.
150See
151.Xr dwarf 3 .
152.It Em libelf
153.Pq Fl l Ns Ar elf
154The ELF access library.
155See
156.Xr elf 3 .
157.It Em libfetch
158.Pq Fl l Ns Ar fetch
159The file transfer library.
160See
161.Xr fetch 3 .
162.It Em libfigpar
163.Pq Fl l Ns Ar figpar
164The configuration file parsing library.
165See
166.Xr figpar 3 .
167.It Em libgpio
168.Pq Fl l Ns Ar gpio
169The general-purpose input output library (GPIO).
170See
171.Xr gpio 3 .
172.It Em libgssapi
173.Pq Fl l Ns Ar gssapi
174The generic security service application programming
175interface.
176See
177.Xr gssapi 3 .
178.It Em libjail
179.Pq Fl l Ns Ar jail
180The jail library.
181See
182.Xr jail 3 .
183.It Em libkvm
184.Pq Fl l Ns Ar kvm
185Functions used to access kernel memory are in this library.
186They can be used
187against both a running system and a crash dump.
188See
189.Xr kvm 3 .
190.It Em libl
191.Pq Fl l Ns Ar l
192The library for
193.Xr lex 1 .
194.It Em libm
195.Pq Fl l Ns Ar m
196The math library.
197See
198.Xr math 3 .
199.It Em libmd
200.Pq Fl l Ns Ar md
201The message digest library.
202See
203.Xr md4 3 ,
204.Xr md5 3 ,
205.Xr sha 3 ,
206.Xr sha256 3 ,
207.Xr sha512 3 ,
208.Xr ripemd 3 ,
209.Xr skein 3 .
210.It Em libmp
211.Pq Fl l Ns Ar mp
212.It Em libpam
213.Pq Fl l Ns Ar pam
214The pluggable authentication module library.
215See
216.Xr pam 3 .
217.It Em libpcap
218.Pq Fl l Ns Ar pcap
219The packet capture library.
220See
221.Xr pcap 3 .
222.It Em libpmc
223.Pq Fl l Ns Ar pmc
224The performance counters library.
225See
226.Xr pmc 3 .
227.It Em libpthread
228.Pq Fl l Ns Ar pthread
229The POSIX threads library.
230See
231.Xr pthread 3 .
232.It Em libstdthreads
233.Pq Fl l Ns Ar stdthreads
234The ISO C11 standard
235.In threads.h
236library.
237See
238.Xr thrd_create 3 .
239.It Em libsysdecode
240.Pq Fl l Ns Ar sysdecode
241The system argument decoding library.
242See
243.Xr sysdecode 3 .
244.It Em libtermcap
245.Pq Fl l Ns Ar termcap
246The terminal independent operation library package.
247See
248.Xr termcap 3 .
249.It Em libusb
250.Pq Fl l Ns Ar usb
251The USB access library.
252See
253.Xr usb 3 .
254.It Em libvgl
255.Pq Fl l Ns Ar vgl
256The video graphics library.
257See
258.Xr vgl 3 .
259.It Em liby
260.Pq Fl l Ns Ar y
261The library for
262.Xr yacc 1 .
263.It Em libz
264.Pq Fl l Ns Ar z
265The general-purpose data compression library.
266See
267.Xr zlib 3 .
268.El
269.Sh FILES
270.Bl -tag -width /usr/lib/libm_p.a -compact
271.It Pa /usr/lib/libc.a
272the C library
273.It Pa /usr/lib/libc_p.a
274the C library compiled for profiling
275.It Pa /usr/lib/libm.a
276the math library
277.It Pa /usr/lib/libm_p.a
278the math library compiled for profiling
279.El
280.Sh LIBRARY TYPES
281The system libraries are located in
282.Pa /lib
283and
284.Pa /usr/lib .
285A library has the following naming convention:
286.Bd -unfilled -offset indent
287libc.so.7
288.Ed
289.Pp
290Libraries with an
291.Sq .a
292suffix are static.
293When a program is linked against a static library, all necessary library code
294will be included in the binary.
295This means the binary can be run even when the libraries are unavailable.
296However, it can be inefficient with both disk space and memory usage
297during execution.
298The C compiler,
299.Xr cc 1 ,
300can be instructed to link statically by specifying the
301.Fl static
302flag.
303.Pp
304Libraries with a
305.Sq .so.X
306suffix are dynamic libraries.
307When code is linked dynamically, the library code that the application needs
308is not included in the binary.
309Instead, data structures are added containing information about which dynamic
310libraries to link with.
311When the binary is executed, the run-time linker
312.Xr ld.so 1
313reads these data structures and loads them into the
314process virtual address space.
315.Xr rtld 1
316loads the shared libraries when the program is executed.
317.Pp
318.Sq X
319represents the library version number of the library.
320In the example above, a binary linked with
321.Pa libc.so.8
322would not be usable on a system where only
323.Pa libc.so.7
324is available.
325.Pp
326The advantages of dynamic libraries are that multiple instances of the same
327library can share address space, and the physical size of the binary is
328smaller.
329A namespace per shared library is available via hidden visibility,
330allowing multiple compilation units in a library to share things without
331making them available to other libraries.
332It is possible to load libraries dynamically via
333.Xr dlopen 3 .
334The disadvantage is the added complexity that comes with loading the
335libraries dynamically, and the extra time taken to load the libraries.
336Of course, if the libraries are not available, the binary will be unable
337to execute.
338Calls across shared libraries are also slightly slower and cannot be
339inlined, not even with link time optimization.
340The C compiler,
341.Xr cc 1 ,
342can be instructed to link dynamically by specifying the
343.Fl shared
344flag.
345.Pp
346Shared libraries, as well as static libraries on architectures which produce
347position-independent executables
348.Pq PIEs
349by default, contain position-independent code
350.Pq PIC .
351Normally, compilers produce relocatable code.
352Relocatable code needs to be modified at run-time, depending on where in
353memory it is to be run.
354The C compiler,
355.Xr cc 1 ,
356can be instructed to generate PIC code by specifying the
357.Fl fPIC
358flag.
359.Pp
360Static libraries are generated using the
361.Xr ar 1
362utility.
363The libraries contain an index to the contents of the library,
364stored within the library itself.
365The index lists each symbol defined by a member of a library that is a
366relocatable object file.
367This speeds up linking to the library, and allows routines in the library
368to call each other regardless of their placement within the library.
369.Sh SEE ALSO
370.Xr ar 1 ,
371.Xr cc 1 ,
372.Xr ld 1 ,
373.Xr nm 1 ,
374.Xr intro 2 ,
375.Xr math 3 ,
376.Xr stdio 3 ,
377.Xr make.conf 5 ,
378.Xr src.conf 5
379.Sh HISTORY
380An
381.Nm
382manual appeared in
383.At v7 .
384