1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
|
.\" $OpenBSD: intro.3,v 1.56 2013/07/11 07:02:06 ajacoutot Exp $
.\" $NetBSD: intro.3,v 1.5 1995/05/10 22:46:24 jtc Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)intro.3 8.1 (Berkeley) 6/5/93
.\"
.Dd $Mdocdate: July 11 2013 $
.Dt INTRO 3
.Os
.Sh NAME
.Nm intro
.Nd introduction to the C libraries
.Sh SYNOPSIS
.Nm cc
.Op Ar flags
.Ar
.Op Fl llibrary
.Sh DESCRIPTION
The manual pages in section 3 provide an overview of the C library
functions, their error returns, and other common definitions and concepts.
Most of these functions are available from the C library,
.Em libc .
Other libraries, such as the math library,
.Em libm ,
must be indicated at compile time with the
.Fl l
option of the compiler.
.Pp
The various libraries (followed by the loader flag):
.Pp
.Bl -tag -width "libkvm" -compact
.It libasn1 Pq Fl lasn1
The abstract syntax notation (ASN) library provides routines for the
specification of abstract data types.
.Pp
.It libc Pq Fl lc
Standard C library functions.
When using the C compiler
.Xr cc 1 ,
it is not necessary to supply the loader flag
.Fl lc
for these functions.
There are several
.Dq libraries
or groups of functions included inside of libc: the standard
.Tn I/O
routines,
database routines,
bit operators,
string operators,
character tests and character operators,
DES encryption routines,
storage allocation,
time functions,
signal handling,
and more.
.Pp
.It libcom_err Pq Fl lcom_err
The common error description library.
.Pp
.It libcompat Pq Fl lcompat
Functions which are obsolete but are available for compatibility with
.Bx 4.3 .
In particular, a number of system call interfaces provided in previous
releases of
.Bx
have been included for source code compatibility.
Use of these routines should, for the most part, be avoided.
The manual page entry for each compatibility routine
indicates the proper interface to use.
.Pp
.It libcrypto Pq Fl lcrypto
The OpenSSL crypto library.
Implements a range of cryptographic algorithms,
providing such functionality as symmetric encryption, public key cryptography,
and certificate handling.
See
.Xr crypto 3 .
.Pp
.It libcurses Pq Fl lcurses
.It libncurses Pq Fl lncurses
.It libncursesw Pq Fl lncursesw
.It libtermcap Pq Fl ltermcap
.It libtermlib Pq Fl ltermlib
Terminal-independent screen management routines for two-dimensional
non-bitmap display terminals.
This implementation is
.Dq new curses
and is a replacement for
.Bx 4.2
classic curses.
The libraries
.Em libncurses ,
.Em libncursesw ,
.Em libtermcap ,
and
.Em libtermlib
are all hard links to
.Em libcurses .
This is for compatibility purposes only;
new programs should link with
.Fl lcurses .
See
.Xr curses 3
and
.Xr termcap 3 .
.Pp
.It libedit Pq Fl ledit
Generic line editing and history functions, similar to those found in
.Xr sh 1 .
Functions using the
.Em libedit
library must be linked with the
.Em libcurses
library, i.e.\&
.Fl ledit lcurses .
See
.Xr editline 3 .
.Pp
.It libevent Pq Fl levent
Provides a mechanism to execute a function when a specific event on a
file descriptor occurs or after a given time has passed.
See
.Xr event 3 .
.Pp
.It libexpat Pq Fl lexpat
Library routines for parsing XML documents.
.Pp
.It libform Pq Fl lform
.It libformw Pq Fl lformw
Terminal-independent facilities for composing form screens on
character-cell terminals.
Functions using the
.Em libform
library must be linked with the
.Em libcurses
library, i.e.\&
.Fl lform lcurses .
.Em libformw
is a hard link to
.Em libform
intended for use with
.Em libncursesw
wide-character functions.
See
.Xr form 3 .
.Pp
.It libgcc Pq Fl lgcc
GCC runtime support,
including long arithmetic, propolice,
and language independent exception support.
Note: users do not normally have to explicitly link with this library.
.Pp
.It libgssapi Pq Fl lgssapi
The Generic Security Service Application Program Interface
.Pq GSS-API
provides security services to callers in a generic fashion.
See
.Xr gssapi 3 .
.Pp
.It libhdb Pq Fl lhdb
The Heimdal Kerberos 5 authentication/authorisation database access
library.
.Pp
.It libiberty Pq Fl liberty
Collection of subroutines missing in other operating systems,
as well as the C++ demangler and other functions used by
the GNU toolchain.
.Pp
.It libkadm5clnt Pq Fl lkadm5clnt
Kerberos administration client library,
for talking to a Kerberos database.
Clients communicate via the network.
.Pp
.It libkadm5srv Pq Fl lkadm5srv
Kerberos administration server library,
for talking to a Kerberos database.
Servers talk directly to the database.
.Pp
.It libkafs5 Pq Fl lkafs5
The Kerberos 5 AFS library.
See
.Xr kafs5 3 .
.Pp
.It libkeynote Pq Fl lkeynote
System library for the keynote trust-management system.
Trust-management systems provide standard, general-purpose mechanisms
for specifying application security policies and credentials.
Functions using the libkeynote library must be linked with the
.Em libm
and
.Em libcrypto
libraries, i.e.\&
.Fl lkeynote lm lcrypto .
See
.Xr keynote 3
and
.Xr keynote 4 .
.Pp
.It libkrb5 Pq Fl lkrb5
Kerberos 5 library.
See
.Xr krb5 3 .
.Pp
.It libkvm Pq Fl lkvm
Kernel memory interface library.
Provides a uniform interface for accessing kernel virtual memory images,
including live systems and crash dumps.
See
.Xr kvm 3 .
.Pp
.It libl Pq Fl l\&l
.It libfl Pq Fl lfl
The library for
.Xr lex 1 ,
a lexical analyzer generator.
The
.Em libfl
library
is a hard link to
.Em libl .
.Pp
.It libm Pq Fl lm
Mathematical functions which comprise the C math library,
.Em libm .
.Pp
.It libmenu Pq Fl lmenu
.It libmenuw Pq Fl lmenuw
Terminal-independent facilities for composing menu systems on
character-cell terminals.
Functions using the
.Em libmenu
library must be linked with the
.Em libcurses
library, i.e.\&
.Fl lmenu lcurses .
.Em libmenuw
is a hard link to
.Em libmenu
intended for use with
.Em libncursesw
wide-character functions.
See
.Xr menu 3 .
.Pp
.It libmilter Pq Fl lmilter
The
.Xr sendmail 8
mail filter API.
See the documentation in
.Pa /usr/share/doc/html/milter/ .
.Pp
.It libobjc Pq Fl lobjc
Library for Objective C, an object-oriented superset of ANSI C.
Use this to compile Objective C programs.
.Pp
.It libocurses Pq Fl locurses
.It libotermcap Pq Fl lotermcap
Routines to provide the user with a method of updating screens
with reasonable optimisation.
The
.Xr ocurses 3
library is compatible with the
.Em curses
library provided in 4.3.
.Em libotermcap
is the 4.3-compatible
.Em termcap
library, and is a hard link to
.Em libocurses .
See
.Xr otermcap 3 .
.Pp
.It libossaudio Pq Fl lossaudio
Provides an emulation of the OSS
.Pq Linux
audio interface.
This is used only for porting programs.
See
.Xr ossaudio 3 .
.Pp
.It libpanel Pq Fl lpanel
.It libpanelw Pq Fl lpanelw
Terminal-independent facilities for stacked windows on
character-cell terminals.
Functions using the
.Em libpanel
library must be linked with the
.Em libcurses
library, i.e.\&
.Fl lpanel lcurses .
.Em libpanelw
is a hard link to
.Em libpanel
intended for use with
.Em libncursesw
wide-charcter functions.
See
.Xr panel 3 .
.Pp
.It libpcap Pq Fl lpcap
Packet capture library.
All packets on the network, even those destined for other hosts,
are accessible through this library.
See
.Xr pcap 3 .
.Pp
.It libperl Pq Fl lperl
Support routines for
.Xr perl 1 .
.Pp
.It libpthread Pq Fl lpthread
.St -p1003.1-2001
threads API.
See
.Xr pthreads 3 .
.Pp
.It libreadline Pq Fl lreadline
Command line editing interface.
See
.Xr readline 3 .
.Pp
.It libroken Pq Fl lroken
A library containing compatibility functions used by Kerberos.
It implements functionality required by the Kerberos implementation not
implemented in the standard
.Ox
libraries.
.Pp
.It librpcsvc Pq Fl lrpcsvc
Generated by
.Xr rpcgen 1 ,
containing stub functions for many common
.Xr rpc 3
protocols.
.Pp
.It libskey Pq Fl lskey
Support library for the S/Key one time password
.Pq OTP
authentication toolkit.
See
.Xr skey 3 .
.Pp
.It libsndio Pq Fl lsndio
Library for
.Xr audio 4
hardware and the
.Xr aucat 1
audio server.
See
.Xr sio_open 3 .
.Pp
.It libsqlite3 Pq Fl lsqlite3
SQL database library.
See
.Xr sqlite3 1 .
.Pp
.It libssl Pq Fl lssl
The OpenSSL ssl library implements the Secure Sockets Layer
.Pq SSL v3
and Transport Layer Security
.Pq TLS v1
protocols.
See
.Xr ssl 3 .
.Pp
.It libstdc++ Pq Fl lstdc++
GCC subroutine library for C++.
See
.Xr c++ 1 .
Note: users do not normally have to explicitly link with this library.
.Pp
.It libsupc++ Pq Fl lsupc++
(non GCC 2.95 systems only)
C++ core language support
(exceptions, new, typeinfo).
Note: users do not normally have to explicitly link with this library.
.Pp
.It libusbhid Pq Fl lusbhid
Routines to extract data from USB Human Interface Devices
.Pq HIDs .
See
.Xr usbhid 3 .
.Pp
.It libutil Pq Fl lutil
System utility functions.
These are currently
.Xr check_expire 3 ,
.Xr fmt_scaled 3 ,
.Xr fparseln 3 ,
.Xr getmaxpartitions 3 ,
.Xr getrawpartition 3 ,
.Xr imsg_init 3 ,
.Xr login 3 ,
.Xr login_fbtab 3 ,
.Xr opendev 3 ,
.Xr opendisk 3 ,
.Xr openpty 3 ,
.Xr pidfile 3 ,
.Xr pkcs5_pbkdf2 3 ,
.Xr pw_init 3 ,
.Xr pw_lock 3 ,
.Xr readlabelfs 3
and
.Xr uucplock 3 .
.Pp
.It libwind Pq Fl lwind
Heimdal Kerberos 5 implementation of stringprep and some of its profiles.
.Pp
.It libwrap Pq Fl lwrap
TCP wrapper access control library.
See
.Xr hosts_access 3
and
.Xr rfc1413 3 .
.Pp
.It liby Pq Fl ly
The library for
.Xr yacc 1 ,
an LALR parser generator.
.Pp
.It libz Pq Fl lz
General purpose data compression library.
The functions in this library are documented in
.Xr compress 3 .
The data format is described in RFCs 1950 \- 1952.
.El
.Pp
Platform-specific libraries:
.Bl -tag -width "libkvm"
.It libalpha Pq Fl lalpha
Alpha I/O and memory access functions.
See
.Xr inb 2 .
.It libamd64 Pq Fl lamd64
AMD64 I/O and memory access functions.
See
.Xr amd64_iopl 2 .
.It libarm Pq Fl larm
ARM I/O and memory access functions.
See
.Xr arm_drain_writebuf 2
and
.Xr arm_sync_icache 2 .
.It libi386 Pq Fl li386
i386 I/O and memory access functions.
See
.Xr i386_get_ioperm 2 ,
.Xr i386_get_ldt 2 ,
.Xr i386_iopl 2 ,
and
.Xr i386_vm86 2 .
.El
.Sh LIBRARY TYPES
The system libraries are located in
.Pa /usr/lib .
Typically, a library will have a number of variants:
.Bd -unfilled -offset indent
libc.a
libc_p.a
libc.so.30.1
.Ed
.Pp
Libraries with an
.Sq .a
suffix are static.
When a program is linked against a library, all the library code
will be linked into the binary.
This means the binary can be run even when the libraries are unavailable.
However, it can be inefficient with memory usage.
The C compiler,
.Xr cc 1 ,
can be instructed to link statically by specifying the
.Fl static
flag.
.Pp
Libraries with a
.Sq _p.a
suffix are profiling libraries.
They contain extra information suitable for analysing programs,
such as execution speed and call counts.
This in turn can be interpreted by utilities such as
.Xr gprof 1 .
The C compiler,
.Xr cc 1 ,
can be instructed to generate profiling code,
or to link with profiling libraries, by specifying the
.Fl pg
flag.
.Pp
Libraries with a
.Sq .so.X.Y
suffix are dynamic libraries.
When code is compiled dynamically, the library code that the application needs
is not linked into the binary.
Instead, data structures are added containing information about which dynamic
libraries to link with.
When the binary is executed, the run-time linker
.Xr ld.so 1
reads these data structures, and loads them at a virtual address using the
.Xr mmap 2
system call.
.Pp
.Sq X
represents the major number of the library, and
.Sq Y
represents the minor number.
In general, a binary will be able to use a dynamic library with a differing
minor number, but the major numbers must match.
In the example above, a binary linked with minor number
.Sq 3
would be linkable against libc.so.30.1,
while a binary linked with major number
.Sq 31
would not.
.Pp
The advantages of dynamic libraries are that multiple instances of the same
program can share address space, and the physical size of the binary is
smaller.
The disadvantage is the added complexity that comes with loading the
libraries dynamically, and the extra time taken to load the libraries.
Of course, if the libraries are not available, the binary will be unable
to execute.
The C compiler,
.Xr cc 1 ,
can be instructed to link dynamically by specifying the
.Fl shared
flag, although on systems that support it, this will be the default and
need not be specified.
.Pp
Shared libraries, as well as static libraries on architectures which produce
position-independent executables
.Pq PIEs
by default, contain position-independent code
.Pq PIC .
Normally, compilers produce relocatable code.
Relocatable code needs to be modified at run-time, depending on where in
memory it is to be run.
PIC code does not need to be modified at run-time, but is less efficient than
relocatable code.
The C compiler,
.Xr cc 1 ,
can be instructed to generate PIC code by specifying the
.Fl fpic
or
.Fl fPIC
flags.
.Pp
With the exception of dynamic libraries, libraries are generated using the
.Xr ar 1
utility.
The libraries contain an index to the contents of the library,
stored within the library itself.
The index lists each symbol defined by a member of a library that is a
relocatable object file.
This speeds up linking to the library, and allows routines in the library
to call each other regardless of their placement within the library.
The index is created by
.Xr ranlib 1
and can be viewed using
.Xr nm 1 .
.Pp
The building of dynamic libraries can be prevented by setting the variable
.Dv NOPIC
in
.Pa /etc/mk.conf .
The building of profiling versions of libraries can
be prevented by setting the variable
.Dv NOPROFILE
in
.Pa /etc/mk.conf .
See
.Xr mk.conf 5
for more details.
.Sh SEE ALSO
.Xr ar 1 ,
.Xr cc 1 ,
.Xr gcc-local 1 ,
.Xr gprof 1 ,
.Xr ld 1 ,
.Xr ld.so 1 ,
.Xr nm 1 ,
.Xr ranlib 1 ,
.Xr mk.conf 5
.Sh HISTORY
An
.Nm
manual appeared in
.At v7 .
|