xref: /openbsd-src/share/man/man3/intro.3 (revision 7350f337b9e3eb4461d99580e625c7ef148d107c)
1.\"	$OpenBSD: intro.3,v 1.90 2019/05/15 19:00:47 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: May 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 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.
353.Pp
354.It liby Pq Fl ly
355The library for
356.Xr yacc 1 ,
357an LALR parser generator.
358.Pp
359.It libz Pq Fl lz
360General purpose data compression library.
361The functions in this library are documented in
362.Xr compress 3 .
363The data format is described in RFCs 1950 \- 1952.
364.El
365.Pp
366Platform-specific libraries:
367.Bl -tag -width "libkvm"
368.It libalpha Pq Fl lalpha
369Alpha I/O and memory access functions.
370See
371.Xr inb 2 .
372.It libamd64 Pq Fl lamd64
373AMD64 I/O and memory access functions.
374See
375.Xr amd64_iopl 2 .
376.It libi386 Pq Fl li386
377i386 I/O and memory access functions.
378See
379.Xr i386_iopl 2 .
380.El
381.Sh LIBRARY TYPES
382The system libraries are located in
383.Pa /usr/lib .
384Typically, a library will have a number of variants:
385.Bd -unfilled -offset indent
386libc.a
387libc_p.a
388libc.so.30.1
389.Ed
390.Pp
391Libraries with an
392.Sq .a
393suffix are static.
394When a program is linked against a library, all the library code
395will be linked into the binary.
396This means the binary can be run even when the libraries are unavailable.
397However, it can be inefficient with memory usage.
398The C compiler,
399.Xr cc 1 ,
400can be instructed to link statically by specifying the
401.Fl static
402flag.
403.Pp
404Libraries with a
405.Sq _p.a
406suffix are profiling libraries.
407They contain extra information suitable for analysing programs,
408such as execution speed and call counts.
409This in turn can be interpreted by utilities such as
410.Xr gprof 1 .
411The C compiler,
412.Xr cc 1 ,
413can be instructed to generate profiling code,
414or to link with profiling libraries, by specifying the
415.Fl pg
416flag.
417.Pp
418Libraries with a
419.Sq .so.X.Y
420suffix are dynamic libraries.
421When code is compiled dynamically, the library code that the application needs
422is not linked into the binary.
423Instead, data structures are added containing information about which dynamic
424libraries to link with.
425When the binary is executed, the run-time linker
426.Xr ld.so 1
427reads these data structures, and loads them at a virtual address using the
428.Xr mmap 2
429system call.
430.Pp
431.Sq X
432represents the major number of the library, and
433.Sq Y
434represents the minor number.
435In general, a binary will be able to use a dynamic library with a differing
436minor number, but the major numbers must match.
437In the example above, a binary linked with minor number
438.Sq 3
439would be linkable against libc.so.30.1,
440while a binary linked with major number
441.Sq 31
442would not.
443.Pp
444The advantages of dynamic libraries are that multiple instances of the same
445program can share address space, and the physical size of the binary is
446smaller.
447The disadvantage is the added complexity that comes with loading the
448libraries dynamically, and the extra time taken to load the libraries.
449Of course, if the libraries are not available, the binary will be unable
450to execute.
451The C compiler,
452.Xr cc 1 ,
453can be instructed to link dynamically by specifying the
454.Fl shared
455flag, although on systems that support it, this will be the default and
456need not be specified.
457.Pp
458Shared libraries, as well as static libraries on architectures which produce
459position-independent executables
460.Pq PIEs
461by default, contain position-independent code
462.Pq PIC .
463Normally, compilers produce relocatable code.
464Relocatable code needs to be modified at run-time, depending on where in
465memory it is to be run.
466PIC code does not need to be modified at run-time, but is less efficient than
467relocatable code.
468The C compiler,
469.Xr cc 1 ,
470can be instructed to generate PIC code by specifying the
471.Fl fpic
472or
473.Fl fPIC
474flags.
475.Pp
476With the exception of dynamic libraries, libraries are generated using the
477.Xr ar 1
478utility.
479The libraries contain an index to the contents of the library,
480stored within the library itself.
481The index lists each symbol defined by a member of a library that is a
482relocatable object file.
483This speeds up linking to the library, and allows routines in the library
484to call each other regardless of their placement within the library.
485The index is created by
486.Xr ranlib 1
487and can be viewed using
488.Xr nm 1 .
489.Pp
490The building of dynamic libraries can be prevented by setting the variable
491.Dv NOPIC
492in
493.Pa /etc/mk.conf .
494The building of profiling versions of libraries can
495be prevented by setting the variable
496.Dv NOPROFILE
497in
498.Pa /etc/mk.conf .
499See
500.Xr mk.conf 5
501for more details.
502.Sh SEE ALSO
503.Xr ar 1 ,
504.Xr cc 1 ,
505.Xr gprof 1 ,
506.Xr ld 1 ,
507.Xr ld.so 1 ,
508.Xr nm 1 ,
509.Xr ranlib 1 ,
510.Xr mk.conf 5
511.Sh HISTORY
512An
513.Nm
514manual for section 3 first appeared in
515.At v7 .
516