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