xref: /openbsd/share/man/man3/intro.3 (revision 73471bf0)
1.\"	$OpenBSD: intro.3,v 1.96 2021/06/10 13:13:38 jmc Exp $
2.\"	$NetBSD: intro.3,v 1.5 1995/05/10 22:46:24 jtc Exp $
3.\"
4.\" Copyright (c) 1980, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)intro.3	8.1 (Berkeley) 6/5/93
32.\"
33.Dd $Mdocdate: June 10 2021 $
34.Dt INTRO 3
35.Os
36.Sh NAME
37.Nm intro
38.Nd introduction to the C libraries
39.Sh SYNOPSIS
40.Nm cc
41.Op Ar flags
42.Ar
43.Op Fl llibrary
44.Sh DESCRIPTION
45The manual pages in section 3 provide an overview of the C library
46functions, their error returns, and other common definitions and concepts.
47Most of these functions are available from the C library,
48.Em libc .
49Other libraries, such as the math library,
50.Em libm ,
51must be indicated at compile time with the
52.Fl l
53option of the compiler.
54.Pp
55The various libraries (followed by the loader flag):
56.Pp
57.Bl -tag -width "libkvm" -compact
58.It libLLVM Pq Fl lLLVM
59LLVM components in a single library.
60.Pp
61.It libagentx Pq Fl lagentx
62AgentX client library.
63Used for applications to export metrics to AgentX capable snmp daemons.
64See
65.Xr agentx 3 .
66.Pp
67.It libc Pq Fl lc
68Standard C library functions.
69When using the C compiler
70.Xr cc 1 ,
71it is not necessary to supply the loader flag
72.Fl lc
73for these functions.
74There are several
75.Dq libraries
76or groups of functions included inside of libc: the standard I/O routines,
77database routines,
78bit operators,
79string operators,
80character tests and character operators,
81cryptographic routines,
82storage allocation,
83time functions,
84signal handling,
85and more.
86.Pp
87.It libc++ Pq Fl lc++
88LLVM standard C++ library.
89See
90.Xr clang 1 .
91Note: users do not normally have to explicitly link with this library.
92.Pp
93.It libc++abi Pq Fl lc++abi
94LLVM C++ runtime library.
95Note: users do not normally have to explicitly link with this library.
96.Pp
97.It libcbor Pq Fl lcbor
98An implementation of the Concise Binary Object Representation
99.Pq CBOR
100encoding format defined in RFC 7049.
101.Pp
102.It libcrypto Pq Fl lcrypto
103The OpenSSL crypto library.
104Implements a range of cryptographic algorithms,
105providing such functionality as symmetric encryption, public key cryptography,
106and certificate handling.
107See
108.Xr crypto 3 .
109.Pp
110.It libcurses Pq Fl lcurses
111.It libncurses Pq Fl lncurses
112.It libncursesw Pq Fl lncursesw
113.It libtermcap Pq Fl ltermcap
114.It libtermlib Pq Fl ltermlib
115Terminal-independent screen management routines for two-dimensional
116non-bitmap display terminals.
117This implementation is
118.Dq new curses
119and is a replacement for
120.Bx 4.2
121classic curses.
122The libraries
123.Em libncurses ,
124.Em libncursesw ,
125.Em libtermcap ,
126and
127.Em libtermlib
128are all hard links to
129.Em libcurses .
130This is for compatibility purposes only;
131new programs should link with
132.Fl lcurses .
133See
134.Xr curses 3
135and
136.Xr termcap 3 .
137.Pp
138.It libedit Pq Fl ledit
139Generic line editing and history functions, similar to those found in
140.Xr sh 1 .
141Functions using the
142.Em libedit
143library must be linked with the
144.Em libcurses
145library, i.e.\&
146.Fl ledit lcurses .
147See
148.Xr editline 3 .
149.Pp
150.It libelf Pq Fl lelf
151Library routines for manipulating ELF objects.
152See
153.Xr elf 3 .
154.Pp
155.It libevent Pq Fl levent
156Provides a mechanism to execute a function when a specific event on a
157file descriptor occurs or after a given time has passed.
158See
159.Xr event 3 .
160.Pp
161.It libexecinfo Pq Fl lexecinfo
162Library providing backtrace functions.
163See
164.Xr backtrace 3 .
165.Pp
166.It libexpat Pq Fl lexpat
167Library routines for parsing XML documents.
168.Pp
169.It libfido2 Pq Fl lfido2
170Library for communication with U2F/FIDO2 devices over USB.
171.Pp
172.It libform Pq Fl lform
173.It libformw Pq Fl lformw
174Terminal-independent facilities for composing form screens on
175character-cell terminals.
176Functions using the
177.Em libform
178library must be linked with the
179.Em libcurses
180library, i.e.\&
181.Fl lform lcurses .
182.Em libformw
183is a hard link to
184.Em libform
185intended for use with
186.Em libncursesw
187wide-character functions.
188See
189.Xr form 3 .
190.Pp
191.It libfuse Pq Fl lfuse
192File system in userland library.
193See
194.Xr fuse_main 3 .
195.Pp
196.It libgcc Pq Fl lgcc
197GCC runtime support,
198including long arithmetic, propolice,
199and language independent exception support.
200Note: users do not normally have to explicitly link with this library.
201.Pp
202.It libiberty Pq Fl liberty
203Collection of subroutines missing in other operating systems,
204as well as the C++ demangler and other functions used by
205the GNU toolchain.
206.Pp
207.It libkeynote Pq Fl lkeynote
208System library for the keynote trust-management system.
209Trust-management systems provide standard, general-purpose mechanisms
210for specifying application security policies and credentials.
211Functions using the libkeynote library must be linked with the
212.Em libm
213and
214.Em libcrypto
215libraries, i.e.\&
216.Fl lkeynote lm lcrypto .
217See
218.Xr keynote 3
219and
220.Xr keynote 4 .
221.Pp
222.It libkvm Pq Fl lkvm
223Kernel memory interface library.
224Provides a uniform interface for accessing kernel virtual memory images,
225including live systems and crash dumps.
226See
227.Xr kvm 3 .
228.Pp
229.It libl Pq Fl l\&l
230.It libfl Pq Fl lfl
231The library for
232.Xr lex 1 ,
233a lexical analyzer generator.
234The
235.Em libfl
236library
237is a hard link to
238.Em libl .
239.Pp
240.It libm Pq Fl lm
241Mathematical functions which comprise the C math library,
242.Em libm .
243.Pp
244.It libmenu Pq Fl lmenu
245.It libmenuw Pq Fl lmenuw
246Terminal-independent facilities for composing menu systems on
247character-cell terminals.
248Functions using the
249.Em libmenu
250library must be linked with the
251.Em libcurses
252library, i.e.\&
253.Fl lmenu lcurses .
254.Em libmenuw
255is a hard link to
256.Em libmenu
257intended for use with
258.Em libncursesw
259wide-character functions.
260See
261.Xr menu 3 .
262.Pp
263.It libossaudio Pq Fl lossaudio
264Provides an emulation of the OSS
265.Pq Linux
266audio interface.
267This is used only for porting programs.
268See
269.Xr ossaudio 3 .
270.Pp
271.It libpanel Pq Fl lpanel
272.It libpanelw Pq Fl lpanelw
273Terminal-independent facilities for stacked windows on
274character-cell terminals.
275Functions using the
276.Em libpanel
277library must be linked with the
278.Em libcurses
279library, i.e.\&
280.Fl lpanel lcurses .
281.Em libpanelw
282is a hard link to
283.Em libpanel
284intended for use with
285.Em libncursesw
286wide-character functions.
287See
288.Xr panel 3 .
289.Pp
290.It libpcap Pq Fl lpcap
291Packet capture library.
292All packets on the network, even those destined for other hosts,
293are accessible through this library.
294See
295.Xr pcap_open_live 3 .
296.Pp
297.It libperl Pq Fl lperl
298Support routines for
299.Xr perl 1 .
300.Pp
301.It libpthread Pq Fl lpthread
302.St -p1003.1-2001
303threads API.
304See
305.Xr pthreads 3 .
306.Pp
307.It libradius Pq Fl lradius
308Support routines for the RADIUS library.
309See
310.Xr radius_new_request_packet 3 .
311.Pp
312.It libreadline Pq Fl lreadline
313Command line editing interface.
314See
315.Xr readline 3 .
316.Pp
317.It librpcsvc Pq Fl lrpcsvc
318Generated by
319.Xr rpcgen 1 ,
320containing stub functions for many common
321.Xr rpc 3
322protocols.
323.Pp
324.It libskey Pq Fl lskey
325Support library for the S/Key one time password
326.Pq OTP
327authentication toolkit.
328See
329.Xr skey 3 .
330.Pp
331.It libsndio Pq Fl lsndio
332Library for
333.Xr audio 4
334hardware and the
335.Xr aucat 1
336audio server.
337See
338.Xr sio_open 3 .
339.Pp
340.It libssl Pq Fl lssl
341The OpenSSL ssl library implements the Secure Sockets Layer
342.Pq SSL v3
343and Transport Layer Security
344.Pq TLS v1
345protocols.
346See
347.Xr ssl 3 .
348.Pp
349.It libstdc++ Pq Fl lstdc++
350GNU standard C++ library.
351See
352.Xr g++ 1 .
353Note: users do not normally have to explicitly link with this library.
354.Pp
355.It libsupc++ Pq Fl lsupc++
356GNU C++ runtime library.
357Note: users do not normally have to explicitly link with this library.
358.Pp
359.It libtls Pq Fl ltls
360A Transport Layer Security library with a clean and easy to use interface.
361See
362.Xr tls_init 3 .
363.Pp
364.It libusbhid Pq Fl lusbhid
365Routines to extract data from USB Human Interface Devices
366.Pq HIDs .
367See
368.Xr usbhid 3 .
369.Pp
370.It libutil Pq Fl lutil
371System utility functions.
372.Pp
373.It liby Pq Fl ly
374The library for
375.Xr yacc 1 ,
376an LALR parser generator.
377.Pp
378.It libz Pq Fl lz
379General purpose data compression library.
380The functions in this library are documented in
381.Xr compress 3 .
382The data format is described in RFCs 1950 \- 1952.
383.El
384.Pp
385Platform-specific libraries:
386.Bl -tag -width "libkvm"
387.It libalpha Pq Fl lalpha
388Alpha I/O and memory access functions.
389See
390.Xr inb 2 .
391.It libamd64 Pq Fl lamd64
392AMD64 I/O and memory access functions.
393See
394.Xr amd64_iopl 2 .
395.It libi386 Pq Fl li386
396i386 I/O and memory access functions.
397See
398.Xr i386_iopl 2 .
399.El
400.Sh LIBRARY TYPES
401The system libraries are located in
402.Pa /usr/lib .
403Typically, a library will have a number of variants:
404.Bd -unfilled -offset indent
405libc.a
406libc_p.a
407libc.so.30.1
408.Ed
409.Pp
410Libraries with an
411.Sq .a
412suffix are static.
413When a program is linked against a library, all the library code
414will be linked into the binary.
415This means the binary can be run even when the libraries are unavailable.
416However, it can be inefficient with memory usage.
417The C compiler,
418.Xr cc 1 ,
419can be instructed to link statically by specifying the
420.Fl static
421flag.
422.Pp
423Libraries with a
424.Sq _p.a
425suffix are profiling libraries.
426They contain extra information suitable for analysing programs,
427such as execution speed and call counts.
428This in turn can be interpreted by utilities such as
429.Xr gprof 1 .
430The C compiler,
431.Xr cc 1 ,
432can be instructed to generate profiling code,
433or to link with profiling libraries, by specifying the
434.Fl pg
435flag.
436.Pp
437Libraries with a
438.Sq .so.X.Y
439suffix are dynamic libraries.
440When code is compiled dynamically, the library code that the application needs
441is not linked into the binary.
442Instead, data structures are added containing information about which dynamic
443libraries to link with.
444When the binary is executed, the run-time linker
445.Xr ld.so 1
446reads these data structures, and loads them at a virtual address using the
447.Xr mmap 2
448system call.
449.Pp
450.Sq X
451represents the major number of the library, and
452.Sq Y
453represents the minor number.
454In general, a binary will be able to use a dynamic library with a differing
455minor number, but the major numbers must match.
456In the example above, a binary linked with minor number
457.Sq 3
458would be linkable against libc.so.30.1,
459while a binary linked with major number
460.Sq 31
461would not.
462.Pp
463The advantages of dynamic libraries are that multiple instances of the same
464program can share address space, and the physical size of the binary is
465smaller.
466The disadvantage is the added complexity that comes with loading the
467libraries dynamically, and the extra time taken to load the libraries.
468Of course, if the libraries are not available, the binary will be unable
469to execute.
470The C compiler,
471.Xr cc 1 ,
472can be instructed to link dynamically by specifying the
473.Fl shared
474flag, although on systems that support it, this will be the default and
475need not be specified.
476.Pp
477Shared libraries, as well as static libraries on architectures which produce
478position-independent executables
479.Pq PIEs
480by default, contain position-independent code
481.Pq PIC .
482Normally, compilers produce relocatable code.
483Relocatable code needs to be modified at run-time, depending on where in
484memory it is to be run.
485PIC code does not need to be modified at run-time, but is less efficient than
486relocatable code.
487The C compiler,
488.Xr cc 1 ,
489can be instructed to generate PIC code by specifying the
490.Fl fpic
491or
492.Fl fPIC
493flags.
494.Pp
495With the exception of dynamic libraries, libraries are generated using the
496.Xr ar 1
497utility.
498The libraries contain an index to the contents of the library,
499stored within the library itself.
500The index lists each symbol defined by a member of a library that is a
501relocatable object file.
502This speeds up linking to the library, and allows routines in the library
503to call each other regardless of their placement within the library.
504The index is created by
505.Xr ranlib 1
506and can be viewed using
507.Xr nm 1 .
508.Pp
509The building of dynamic libraries can be prevented by setting the variable
510.Dv NOPIC
511in
512.Pa /etc/mk.conf .
513The building of profiling versions of libraries can
514be prevented by setting the variable
515.Dv NOPROFILE
516in
517.Pa /etc/mk.conf .
518See
519.Xr mk.conf 5
520for more details.
521.Sh SEE ALSO
522.Xr ar 1 ,
523.Xr cc 1 ,
524.Xr gprof 1 ,
525.Xr ld 1 ,
526.Xr ld.so 1 ,
527.Xr nm 1 ,
528.Xr ranlib 1 ,
529.Xr mk.conf 5
530.Sh HISTORY
531An
532.Nm
533manual for section 3 first appeared in
534.At v7 .
535