xref: /openbsd/share/man/man3/intro.3 (revision 8932bfb7)
1.\"	$OpenBSD: intro.3,v 1.45 2011/07/07 13:31:07 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: July 7 2011 $
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 libcompat Pq Fl lcompat
81Functions which are obsolete but are available for compatibility with
82.Bx 4.3 .
83In particular, a number of system call interfaces provided in previous
84releases of
85.Bx
86have been included for source code compatibility.
87Use of these routines should, for the most part, be avoided.
88The manual page entry for each compatibility routine
89indicates the proper interface to use.
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 libevent Pq Fl levent
140Provides a mechanism to execute a function when a specific event on a
141file descriptor occurs or after a given time has passed.
142See
143.Xr event 3 .
144.Pp
145.It libexpat Pq Fl lexpat
146Library routines for parsing XML documents.
147.Pp
148.It libform Pq Fl lform
149.It libformw Pq Fl lformw
150Terminal-independent facilities for composing form screens on
151character-cell terminals.
152Functions using the
153.Em libform
154library must be linked with the
155.Em libcurses
156library, i.e.\&
157.Fl lform lcurses .
158.Em libformw
159is a hard link to
160.Em libform
161intended for use with
162.Em libncursesw
163wide-character functions.
164See
165.Xr form 3 .
166.Pp
167.It libgcc Pq Fl lgcc
168GCC runtime support,
169including long arithmetic, propolice,
170and language independent exception support.
171Note: users do not normally have to explicitly link with this library.
172.Pp
173.It libgssapi Pq Fl lgssapi
174The Generic Security Service Application Program Interface
175.Pq GSS-API
176provides security services to callers in a generic fashion.
177See
178.Xr gssapi 3 .
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 libkadm5clnt Pq Fl lkadm5clnt
186Kerberos administration client library,
187for talking to a Kerberos database.
188Clients communicate via the network.
189.Pp
190.It libkadm5srv Pq Fl lkadm5srv
191Kerberos administration server library,
192for talking to a Kerberos database.
193Servers talk directly to the database.
194.Pp
195.It libkeynote Pq Fl lkeynote
196System library for the keynote trust-management system.
197Trust-management systems provide standard, general-purpose mechanisms
198for specifying application security policies and credentials.
199Functions using the libkeynote library must be linked with the
200.Em libm
201and
202.Em libcrypto
203libraries, i.e.\&
204.Fl lkeynote lm lcrypto .
205See
206.Xr keynote 3
207and
208.Xr keynote 4 .
209.Pp
210.It libkrb5 Pq Fl lkrb5
211.It libasn1 Pq Fl lasn1
212.It libcom_err Pq Fl lcom_err
213.It libhdb Pq Fl lhdb
214.It libkafs Pq Fl lkafs
215Kerberos 5 libraries.
216The libraries
217.Em libasn1 ,
218.Em libcom_err ,
219.Em libhdb ,
220and
221.Em libkafs
222are all hard links to
223.Em libkrb5 .
224See
225.Xr krb5 3 .
226.Pp
227.It libkvm Pq Fl lkvm
228Kernel memory interface library.
229Provides a uniform interface for accessing kernel virtual memory images,
230including live systems and crash dumps.
231See
232.Xr kvm 3 .
233.Pp
234.It libl Pq Fl l\&l
235.It libfl Pq Fl lfl
236The library for
237.Xr lex 1 ,
238a lexical analyzer generator.
239The
240.Em libfl
241library
242is a hard link to
243.Em libl .
244.Pp
245.It libm Pq Fl lm
246Mathematical functions which comprise the C math library,
247.Em libm .
248.Pp
249.It libmenu Pq Fl lmenu
250.It libmenuw Pq Fl lmenuw
251Terminal-independent facilities for composing menu systems on
252character-cell terminals.
253Functions using the
254.Em libmenu
255library must be linked with the
256.Em libcurses
257library, i.e.\&
258.Fl lmenu lcurses .
259.Em libmenuw
260is a hard link to
261.Em libmenu
262intended for use with
263.Em libncursesw
264wide-character functions.
265See
266.Xr menu 3 .
267.Pp
268.It libmilter Pq Fl lmilter
269The
270.Xr sendmail 8
271mail filter API.
272See the documentation in
273.Pa /usr/share/doc/html/milter/ .
274.Pp
275.It libobjc Pq Fl lobjc
276Library for Objective C, an object-oriented superset of ANSI C.
277Use this to compile Objective C programs.
278.Pp
279.It libocurses Pq Fl locurses
280.It libotermcap Pq Fl lotermcap
281Routines to provide the user with a method of updating screens
282with reasonable optimisation.
283The
284.Xr ocurses 3
285library is compatible with the
286.Em curses
287library provided in 4.3.
288.Em libotermcap
289is the 4.3-compatible
290.Em termcap
291library, and is a hard link to
292.Em libocurses .
293See
294.Xr otermcap 3 .
295.Pp
296.It libossaudio Pq Fl lossaudio
297Provides an emulation of the OSS
298.Pq Linux
299audio interface.
300This is used only for porting programs.
301See
302.Xr ossaudio 3 .
303.Pp
304.It libpanel Pq Fl lpanel
305.It libpanelw Pq Fl lpanelw
306Terminal-independent facilities for stacked windows on
307character-cell terminals.
308Functions using the
309.Em libpanel
310library must be linked with the
311.Em libcurses
312library, i.e.\&
313.Fl lpanel lcurses .
314.Em libpanelw
315is a hard link to
316.Em libpanel
317intended for use with
318.Em libncursesw
319wide-charcter functions.
320See
321.Xr panel 3 .
322.Pp
323.It libpcap Pq Fl lpcap
324Packet capture library.
325All packets on the network, even those destined for other hosts,
326are accessible through this library.
327See
328.Xr pcap 3 .
329.Pp
330.It libperl Pq Fl lperl
331Support routines for
332.Xr perl 1 .
333.Pp
334.It libpthread Pq Fl pthread
335.St -p1003.1-2001
336threads API and thread scheduler.
337Threaded applications should use
338.Fl pthread
339not
340.Fl lpthread .
341See
342.Xr pthreads 3 .
343Note: users do not normally have to explicitly link with this library.
344.Pp
345.It libreadline Pq Fl lreadline
346Command line editing interface.
347See
348.Xr readline 3 .
349.Pp
350.It librpcsvc Pq Fl lrpcsvc
351Generated by
352.Xr rpcgen 1 ,
353containing stub functions for many common
354.Xr rpc 3
355protocols.
356.Pp
357.It libskey Pq Fl lskey
358Support library for the S/Key one time password
359.Pq OTP
360authentication toolkit.
361See
362.Xr skey 3 .
363.Pp
364.It libsndio Pq Fl lsndio
365Library for
366.Xr audio 4
367hardware and the
368.Xr aucat 1
369audio server.
370See
371.Xr sio_open 3 .
372.Pp
373.It libssl Pq Fl lssl
374The OpenSSL ssl library implements the Secure Sockets Layer
375.Pq SSL v2/v3
376and Transport Layer Security
377.Pq TLS \&v1
378protocols.
379See
380.Xr ssl 3 .
381.Pp
382.It libstdc++ Pq Fl lstdc++
383GCC subroutine library for C++.
384See
385.Xr c++ 1 .
386Note: users do not normally have to explicitly link with this library.
387.Pp
388.It libsupc++ Pq Fl lsupc++
389(GCC 3.3.x systems only)
390C++ core language support
391(exceptions, new, typeinfo).
392Note: users do not normally have to explicitly link with this library.
393.Pp
394.It libusbhid Pq Fl lusbhid
395Routines to extract data from USB Human Interface Devices
396.Pq HIDs .
397See
398.Xr usbhid 3 .
399.Pp
400.It libutil Pq Fl lutil
401System utility functions.
402These are currently
403.Xr check_expire 3 ,
404.Xr fmt_scaled 3 ,
405.Xr fparseln 3 ,
406.Xr getmaxpartitions 3 ,
407.Xr getrawpartition 3 ,
408.Xr imsg_init 3 ,
409.Xr login 3 ,
410.Xr login_fbtab 3 ,
411.Xr opendev 3 ,
412.Xr opendisk 3 ,
413.Xr openpty 3 ,
414.Xr pidfile 3 ,
415.Xr pw_init 3 ,
416.Xr pw_lock 3 ,
417.Xr readlabelfs 3
418and
419.Xr uucplock 3 .
420.Pp
421.It libwrap Pq Fl lwrap
422TCP wrapper access control library.
423See
424.Xr hosts_access 3
425and
426.Xr rfc1413 3 .
427.Pp
428.It liby Pq Fl ly
429The library for
430.Xr yacc 1 ,
431an LALR parser generator.
432.Pp
433.It libz Pq Fl lz
434General purpose data compression library.
435The functions in this library are documented in
436.Xr compress 3 .
437The data format is described in RFCs 1950 \- 1952.
438.El
439.Pp
440Platform-specific libraries:
441.Bl -tag -width "libkvm"
442.It libalpha Pq Fl lalpha
443Alpha I/O and memory access functions.
444See
445.Xr inb 2 .
446.It libamd64 Pq Fl lamd64
447AMD64 I/O and memory access functions.
448See
449.Xr amd64_get_ioperm 2
450and
451.Xr amd64_iopl 2 .
452.It libarm Pq Fl larm
453ARM I/O and memory access functions.
454See
455.Xr arm_drain_writebuf 2
456and
457.Xr arm_sync_icache 2 .
458.It libi386 Pq Fl li386
459i386 I/O and memory access functions.
460See
461.Xr i386_get_ioperm 2 ,
462.Xr i386_get_ldt 2 ,
463.Xr i386_iopl 2 ,
464and
465.Xr i386_vm86 2 .
466.El
467.Sh LIBRARY TYPES
468The system libraries are located in
469.Pa /usr/lib .
470Typically, a library will have a number of variants:
471.Bd -unfilled -offset indent
472libc.a
473libc.so.30.1
474libc_p.a
475libc_pic.a
476.Ed
477.Pp
478Libraries with an
479.Sq .a
480suffix are static.
481When a program is linked against a library, all the library code
482will be linked into the binary.
483This means the binary can be run even when the libraries are unavailable.
484However, it can be inefficient with memory usage.
485The C compiler,
486.Xr cc 1 ,
487can be instructed to link statically by specifying the
488.Fl static
489flag.
490.Pp
491Libraries with a
492.Sq .so.X.Y
493suffix are dynamic libraries.
494When code is compiled dynamically, the library code that the application needs
495is not linked into the binary.
496Instead, data structures are added containing information about which dynamic
497libraries to link with.
498When the binary is executed, the run-time linker
499.Xr ld.so 1
500reads these data structures, and loads them at a virtual address using the
501.Xr mmap 2
502system call.
503.Pp
504.Sq X
505represents the major number of the library, and
506.Sq Y
507represents the minor number.
508In general, a binary will be able to use a dynamic library with a differing
509minor number, but the major numbers must match.
510In the example above, a binary linked with minor number
511.Sq 3
512would be linkable against libc.so.30.1,
513while a binary linked with major number
514.Sq 31
515would not.
516.Pp
517The advantages of dynamic libraries are that multiple instances of the same
518program can share address space, and the physical size of the binary is
519smaller.
520The disadvantage is the added complexity that comes with loading the
521libraries dynamically, and the extra time taken to load the libraries.
522Of course, if the libraries are not available, the binary will be unable
523to execute.
524The C compiler,
525.Xr cc 1 ,
526can be instructed to link dynamically by specifying the
527.Fl shared
528flag, although on systems that support it, this will be the default and
529need not be specified.
530.Pp
531Libraries with a
532.Sq _p.a
533suffix are profiling libraries.
534They contain extra information suitable for analysing programs,
535such as execution speed and call counts.
536This in turn can be interpreted by utilities such as
537.Xr gprof 1 .
538The C compiler,
539.Xr cc 1 ,
540can be instructed to generate profiling code,
541or to link with profiling libraries, by specifying the
542.Fl pg
543flag.
544.Pp
545Libraries with a
546.Sq _pic.a
547suffix contain position-independent code
548.Pq PIC .
549Normally, compilers produce relocatable code.
550Relocatable code needs to be modified at run-time, depending on where in
551memory it is to be run.
552PIC code does not need to be modified at run-time, but is less efficient than
553relocatable code.
554PIC code is used by shared libraries, which can make them slower.
555The C compiler,
556.Xr cc 1 ,
557can be instructed to generate PIC code,
558or to link with PIC libraries, by specifying the
559.Fl fpic
560or
561.Fl fPIC
562flags.
563.Pp
564With the exception of dynamic libraries, libraries are generated using the
565.Xr ar 1
566utility.
567The libraries contain an index to the contents of the library,
568stored within the library itself.
569The index lists each symbol defined by a member of a library that is a
570relocatable object file.
571This speeds up linking to the library, and allows routines in the library
572to call each other regardless of their placement within the library.
573The index is created by
574.Xr ranlib 1
575and can be viewed using
576.Xr nm 1 .
577.Pp
578The building of PIC versions of libraries and dynamic libraries can be
579prevented by setting the variable
580.Dv NOPIC
581in
582.Pa /etc/mk.conf .
583The building of profiling versions of libraries and/or dynamic libraries can
584be prevented by setting the variable
585.Dv NOPROFILE
586in
587.Pa /etc/mk.conf .
588See
589.Xr mk.conf 5
590for more details.
591.Sh FILES
592.Bl -tag -width /usr/lib/libotermcap.a -compact
593.It Pa /usr/lib/libasn1.a
594.It Pa /usr/lib/libc.a
595.It Pa /usr/lib/libcom_err.a
596.It Pa /usr/lib/libcompat.a
597.It Pa /usr/lib/libcrypto.a
598.It Pa /usr/lib/libcurses.a
599.It Pa /usr/lib/libedit.a
600.It Pa /usr/lib/libevent.a
601.It Pa /usr/lib/libexpat.a
602.It Pa /usr/lib/libfl.a
603.It Pa /usr/lib/libform.a
604.It Pa /usr/lib/libformw.a
605.It Pa /usr/lib/gcc-lib/${ARCH}-unknown-openbsd${OSREV}/${GCCREV}/fpic/libgcc.a
606.It Pa /usr/lib/libgssapi.a
607.It Pa /usr/lib/libhdb.a
608.It Pa /usr/lib/libiberty.a
609.It Pa /usr/lib/libkadm5clnt.a
610.It Pa /usr/lib/libkadm5srv.a
611.It Pa /usr/lib/libkafs.a
612.It Pa /usr/lib/libkeynote.a
613.It Pa /usr/lib/libkrb5.a
614.It Pa /usr/lib/libkvm.a
615.It Pa /usr/lib/libl.a
616.It Pa /usr/lib/libm.a
617.It Pa /usr/lib/libmenu.a
618.It Pa /usr/lib/libmenuw.a
619.It Pa /usr/lib/libmilter.a
620.It Pa /usr/lib/libncurses.a
621.It Pa /usr/lib/libncursesw.a
622.It Pa /usr/lib/libobjc.a
623.It Pa /usr/lib/libocurses.a
624.It Pa /usr/lib/libossaudio.a
625.It Pa /usr/lib/libotermcap.a
626.It Pa /usr/lib/libpanel.a
627.It Pa /usr/lib/libpanelw.a
628.It Pa /usr/lib/libpcap.a
629.It Pa /usr/lib/libperl.a
630.It Pa /usr/lib/libpthread.a
631.It Pa /usr/lib/libreadline.a
632.It Pa /usr/lib/librpcsvc.a
633.It Pa /usr/lib/libskey.a
634.It Pa /usr/lib/libsndio.a
635.It Pa /usr/lib/libssl.a
636.It Pa /usr/lib/libstdc++.a
637.It Pa /usr/lib/libsupc++.a
638.It Pa /usr/lib/libtermcap.a
639.It Pa /usr/lib/libtermlib.a
640.It Pa /usr/lib/libusbhid.a
641.It Pa /usr/lib/libutil.a
642.It Pa /usr/lib/libwrap.a
643.It Pa /usr/lib/liby.a
644.It Pa /usr/lib/libz.a
645.Pp
646.It Pa /usr/lib/libalpha.a
647.It Pa /usr/lib/libamd64.a
648.It Pa /usr/lib/libarm.a
649.It Pa /usr/lib/libi386.a
650.El
651.Sh SEE ALSO
652.Xr ar 1 ,
653.Xr cc 1 ,
654.Xr gcc-local 1 ,
655.Xr gprof 1 ,
656.Xr ld.so 1 ,
657.Xr nm 1 ,
658.Xr ranlib 1 ,
659.Xr mk.conf 5
660.Sh HISTORY
661An
662.Nm
663manual appeared in
664.At v7 .
665