xref: /openbsd-src/share/man/man3/intro.3 (revision f2395cb1695a5673b88774467a81d72810ba4db7)
1.\"	$OpenBSD: intro.3,v 1.100 2024/05/09 17:57:36 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 9 2024 $
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 libagentx Pq Fl lagentx
62AgentX client library.
63Used for applications to export metrics to AgentX capable snmp daemons.
64See
65.Xr agentx 3 .
66.Pp
67.It libc Pq Fl lc
68Standard C library functions.
69When using the C compiler
70.Xr cc 1 ,
71it is not necessary to supply the loader flag
72.Fl lc
73for these functions.
74There are several
75.Dq libraries
76or groups of functions included inside of libc: the standard I/O routines,
77database routines,
78bit operators,
79string operators,
80character tests and character operators,
81cryptographic routines,
82storage allocation,
83time functions,
84signal handling,
85and more.
86.Pp
87.It libc++ Pq Fl lc++
88LLVM standard C++ library.
89Note: users do not normally have to explicitly link with this library.
90.Pp
91.It libc++abi Pq Fl lc++abi
92LLVM C++ runtime library.
93Note: users do not normally have to explicitly link with this library.
94.Pp
95.It libcbor Pq Fl lcbor
96An implementation of the Concise Binary Object Representation
97.Pq CBOR
98encoding format defined in RFC 7049.
99.Pp
100.It libcrypto Pq Fl lcrypto
101Provides functionality such as symmetric encryption, public key cryptography,
102digests, message authentication codes,
103and certificate handling.
104See
105.Xr crypto 3 .
106.Pp
107.It libcurses Pq Fl lcurses
108.It libncurses Pq Fl lncurses
109.It libncursesw Pq Fl lncursesw
110.It libtermcap Pq Fl ltermcap
111.It libtermlib Pq Fl ltermlib
112Terminal-independent screen management routines for two-dimensional
113non-bitmap display terminals.
114This implementation is
115.Dq new curses
116and is a replacement for
117.Bx 4.2
118classic curses.
119The libraries
120.Em libncurses ,
121.Em libncursesw ,
122.Em libtermcap ,
123and
124.Em libtermlib
125are all hard links to
126.Em libcurses .
127This is for compatibility purposes only;
128new programs should link with
129.Fl lcurses .
130See
131.Xr curses 3
132and
133.Xr termcap 3 .
134.Pp
135.It libedit Pq Fl ledit
136Generic line editing and history functions, similar to those found in
137.Xr sh 1 .
138Functions using the
139.Em libedit
140library must be linked with the
141.Em libcurses
142library, i.e.\&
143.Fl ledit lcurses .
144See
145.Xr editline 3 .
146.Pp
147.It libelf Pq Fl lelf
148Library routines for manipulating ELF objects.
149See
150.Xr elf 3 .
151.Pp
152.It libevent Pq Fl levent
153Provides a mechanism to execute a function when a specific event on a
154file descriptor occurs or after a given time has passed.
155See
156.Xr event 3 .
157.Pp
158.It libexecinfo Pq Fl lexecinfo
159Library providing backtrace functions.
160See
161.Xr backtrace 3 .
162.Pp
163.It libexpat Pq Fl lexpat
164Library routines for parsing XML documents.
165.Pp
166.It libfido2 Pq Fl lfido2
167Library for communication with U2F/FIDO2 devices over USB.
168.Pp
169.It libform Pq Fl lform
170.It libformw Pq Fl lformw
171Terminal-independent facilities for composing form screens on
172character-cell terminals.
173Functions using the
174.Em libform
175library must be linked with the
176.Em libcurses
177library, i.e.\&
178.Fl lform lcurses .
179.Em libformw
180is a hard link to
181.Em libform
182intended for use with
183.Em libncursesw
184wide-character functions.
185See
186.Xr form 3 .
187.Pp
188.It libfuse Pq Fl lfuse
189File system in userland library.
190See
191.Xr fuse_main 3 .
192.Pp
193.It libgcc Pq Fl lgcc
194GCC runtime support,
195including long arithmetic, propolice,
196and language independent exception support.
197Note: users do not normally have to explicitly link with this library.
198.Pp
199.It libiberty Pq Fl liberty
200Collection of subroutines missing in other operating systems,
201as well as the C++ demangler and other functions used by
202the GNU toolchain.
203.Pp
204.It libkeynote Pq Fl lkeynote
205System library for the keynote trust-management system.
206Trust-management systems provide standard, general-purpose mechanisms
207for specifying application security policies and credentials.
208Functions using the libkeynote library must be linked with the
209.Em libm
210and
211.Em libcrypto
212libraries, i.e.\&
213.Fl lkeynote lm lcrypto .
214See
215.Xr keynote 3
216and
217.Xr keynote 4 .
218.Pp
219.It libkvm Pq Fl lkvm
220Kernel memory interface library.
221Provides a uniform interface for accessing kernel virtual memory images,
222including live systems and crash dumps.
223See
224.Xr kvm 3 .
225.Pp
226.It libl Pq Fl l\&l
227.It libfl Pq Fl lfl
228The library for
229.Xr lex 1 ,
230a lexical analyzer generator.
231The
232.Em libfl
233library
234is a hard link to
235.Em libl .
236.Pp
237.It libm Pq Fl lm
238Mathematical functions which comprise the C math library,
239.Em libm .
240.Pp
241.It libmenu Pq Fl lmenu
242.It libmenuw Pq Fl lmenuw
243Terminal-independent facilities for composing menu systems on
244character-cell terminals.
245Functions using the
246.Em libmenu
247library must be linked with the
248.Em libcurses
249library, i.e.\&
250.Fl lmenu lcurses .
251.Em libmenuw
252is a hard link to
253.Em libmenu
254intended for use with
255.Em libncursesw
256wide-character functions.
257See
258.Xr menu 3 .
259.Pp
260.It libossaudio Pq Fl lossaudio
261Provides an emulation of the OSS
262.Pq Linux
263audio interface.
264This is used only for porting programs.
265See
266.Xr ossaudio 3 .
267.Pp
268.It libpanel Pq Fl lpanel
269.It libpanelw Pq Fl lpanelw
270Terminal-independent facilities for stacked windows on
271character-cell terminals.
272Functions using the
273.Em libpanel
274library must be linked with the
275.Em libcurses
276library, i.e.\&
277.Fl lpanel lcurses .
278.Em libpanelw
279is a hard link to
280.Em libpanel
281intended for use with
282.Em libncursesw
283wide-character functions.
284See
285.Xr panel 3 .
286.Pp
287.It libpcap Pq Fl lpcap
288Packet capture library.
289All packets on the network, even those destined for other hosts,
290are accessible through this library.
291See
292.Xr pcap_open_live 3 .
293.Pp
294.It libperl Pq Fl lperl
295Support routines for
296.Xr perl 1 .
297.Pp
298.It libpthread Pq Fl lpthread
299.St -p1003.1-2001
300threads API.
301See
302.Xr pthreads 3 .
303.Pp
304.It libradius Pq Fl lradius
305Support routines for the RADIUS library.
306See
307.Xr radius_new_request_packet 3 .
308.Pp
309.It libreadline Pq Fl lreadline
310Command line editing interface.
311See
312.Xr readline 3 .
313.Pp
314.It librpcsvc Pq Fl lrpcsvc
315Generated by
316.Xr rpcgen 1 ,
317containing stub functions for many common
318.Xr rpc 3
319protocols.
320.Pp
321.It libskey Pq Fl lskey
322Support library for the S/Key one time password
323.Pq OTP
324authentication toolkit.
325See
326.Xr skey 3 .
327.Pp
328.It libsndio Pq Fl lsndio
329Library for
330.Xr audio 4
331hardware and the
332.Xr sndiod 8
333audio server.
334See
335.Xr sio_open 3 .
336.Pp
337.It libssl Pq Fl lssl
338Implements the Transport Layer Security
339.Pq TLS
340protocol, the successor to the Secure Sockets Layer (SSL) protocol.
341See
342.Xr ssl 3 .
343.Pp
344.It libstdc++ Pq Fl lstdc++
345GNU standard C++ library.
346Note: users do not normally have to explicitly link with this library.
347.Pp
348.It libsupc++ Pq Fl lsupc++
349GNU C++ runtime library.
350Note: users do not normally have to explicitly link with this library.
351.Pp
352.It libtls Pq Fl ltls
353A Transport Layer Security library with a clean and easy to use interface.
354See
355.Xr tls_init 3 .
356.Pp
357.It libusbhid Pq Fl lusbhid
358Routines to extract data from USB Human Interface Devices
359.Pq HIDs .
360See
361.Xr usbhid 3 .
362.Pp
363.It libutil Pq Fl lutil
364System utility functions.
365.Pp
366.It liby Pq Fl ly
367The library for
368.Xr yacc 1 ,
369an LALR parser generator.
370.Pp
371.It libz Pq Fl lz
372General purpose data compression library.
373The functions in this library are documented in
374.Xr compress 3 .
375The data format is described in RFCs 1950 \- 1952.
376.El
377.Pp
378Platform-specific libraries:
379.Bl -tag -width "libkvm"
380.It libalpha Pq Fl lalpha
381Alpha I/O and memory access functions.
382See
383.Xr inb 2 .
384.It libamd64 Pq Fl lamd64
385AMD64 I/O and memory access functions.
386See
387.Xr amd64_iopl 2 .
388.It libi386 Pq Fl li386
389i386 I/O and memory access functions.
390See
391.Xr i386_iopl 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 gprof 1 ,
518.Xr ld 1 ,
519.Xr ld.so 1 ,
520.Xr nm 1 ,
521.Xr ranlib 1 ,
522.Xr mk.conf 5
523.Sh HISTORY
524An
525.Nm
526manual for section 3 first appeared in
527.At v7 .
528