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