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