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