1.\" $OpenBSD: intro.3,v 1.20 2003/10/23 19:07:54 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 June 5, 1993 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 file ... 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 libbfd Pq Fl lbfd 59GNU binary file descriptor library. 60Allows applications to operate on object files, 61regardless of the object file format. 62See 63.Sq info bfd . 64.Pp 65.It libc Pq Fl lc 66Standard C library functions. 67When using the C compiler 68.Xr cc 1 , 69it is not necessary to supply the loader flag 70.Fl lc 71for these functions. 72There are several 73.Dq libraries 74or groups of functions included inside of libc: the standard 75.Tn I/O 76routines, 77database routines, 78bit operators, 79string operators, 80character tests and character operators, 81DES encryption routines, 82storage allocation, 83time functions, 84signal handling, 85and more. 86.Pp 87.It libcompat Pq Fl lcompat 88Functions which are obsolete but are available for compatibility with 89.Bx 4.3 . 90In particular, a number of system call interfaces provided in previous 91releases of 92.Bx 93have been included for source code compatibility. 94Use of these routines should, for the most part, be avoided. 95The manual page entry for each compatibility routine 96indicates the proper interface to use. 97.Pp 98.It libcrypto Pq Fl lcrypto 99The OpenSSL crypto library. 100Implements a range of cryptographic algorithms, 101providing such functionality as symmetric encryption, public key cryptography, 102and certificate handling. 103See 104.Xr crypto 3 . 105.Pp 106.It libcurses Pq Fl lcurses 107.It libncurses Pq Fl lncurses 108.It libtermcap Pq Fl ltermcap 109.It libtermlib Pq Fl ltermlib 110Terminal-independent screen management routines for two-dimensional 111non-bitmap display terminals. 112This implementation is 113.Dq new curses 114and is a replacement for 115.Bx 4.2 116classic curses. 117The libraries 118.Em libncurses , 119.Em libtermcap , 120and 121.Em libtermlib 122are all hard links to 123.Em libcurses . 124This is for compatibility purposes only; 125new programs should link with 126.Fl lcurses . 127See 128.Xr curses 3 129and 130.Xr termcap 3 . 131.Pp 132.It libcurses++ Pq Fl lcurses++ 133C++ interface to ncurses routines. 134See 135.Xr curses 3 . 136.Pp 137.It libdes Pq Fl ldes 138Implementation of the 139.Tn DES 140encryption algorithm. 141See 142.Xr des_crypt 3 . 143.Pp 144.It libedit Pq Fl ledit 145Generic line editing and history functions, similar to those found in 146.Xr sh 1 . 147Functions using the 148.Em libedit 149library must be linked with the 150.Em libcurses 151library, i.e.\& 152.Fl ledit lcurses . 153See 154.Xr editline 3 . 155.Pp 156.It libevent Pq Fl levent 157Provides a mechanism to execute a function when a specific event on a 158file descriptor occurs or after a given time has passed. 159See 160.Xr event 3 . 161.Pp 162.It libform Pq Fl lform 163Terminal-independent facilities for composing form screens on 164character-cell terminals. 165Functions using the 166.Em libform 167library must be linked with the 168.Em libcurses 169library, i.e.\& 170.Fl lform lcurses . 171See 172.Xr form 3 . 173.Pp 174.It libfrtbegin Pq Fl lfrtbegin 175.It libg2c Pq Fl lg2c 176Support routines for Fortran functions. 177These two libraries were separated to allow linking Fortran code 178with other languages on ELF platforms. 179See 180.Xr g77 1 . 181.Pp 182.It libgssapi Pq Fl lgssapi 183The Generic Security Service Application Program Interface 184.Pq GSS-API 185provides security services to callers in a generic fashion. 186.\" See 187.\" .Xr gssapi 3 . 188.Pp 189.It libiberty Pq Fl liberty 190Collection of subroutines missing in other operating systems, 191as well as the C++ demangler and other functions used by 192the GNU toolchain. 193.Pp 194.It libkadm5clnt Pq Fl lkadm5clnt 195Kerberos administration client library, 196for talking to a Kerberos database. 197Clients communicate via the network. 198.Pp 199.It libkadm5srv Pq Fl lkadm5srv 200Kerberos administration server library, 201for talking to a Kerberos database. 202Servers talk directly to the database. 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 libkrb5 Pq Fl lkrb5 220.It libasn1 Pq Fl lasn1 221.It libcom_err Pq Fl lcom_err 222.It libhdb Pq Fl lhdb 223.It libkafs Pq Fl lkafs 224Kerberos 5 libraries. 225The libraries 226.Em libasn1 , 227.Em libcom_err , 228.Em libhdb , 229and 230.Em libkafs 231are all hard links to 232.Em libkrb5 . 233See 234.Sq info heimdal . 235.Pp 236.It libkvm Pq Fl lkvm 237Kernel memory interface library. 238Provides a uniform interface for accessing kernel virtual memory images, 239including live systems and crash dumps. 240See 241.Xr kvm 3 . 242.Pp 243.It libl Pq Fl l\&l 244.It libfl Pq Fl lfl 245The library for 246.Xr lex 1 , 247a lexical analyzer generator. 248The 249.Em libfl 250library 251is a hard link to 252.Em libl . 253.Pp 254.It libm Pq Fl lm 255Mathematical functions which comprise the C math library, 256.Em libm . 257See 258.Xr math 3 . 259.Pp 260.It libmenu Pq Fl lmenu 261Terminal-independent facilities for composing menu systems on 262character-cell terminals. 263Functions using the 264.Em libmenu 265library must be linked with the 266.Em libcurses 267library, i.e.\& 268.Fl lmenu lcurses . 269See 270.Xr menu 3 . 271.Pp 272.It libmmalloc Pq Fl lmmalloc 273GNU memory-mapped malloc package. 274In this implementation, 275.Xr mmap 2 276is used to obtain memory from the system, 277rather than 278.Xr sbrk 2 . 279See 280.Sq info mmalloc . 281.Pp 282.It libobjc Pq Fl lobjc 283Library for Objective C, an object-oriented superset of ANSI C. 284Use this to compile Objective C programs. 285.Pp 286.It libocurses Pq Fl locurses 287.It libotermcap Pq Fl lotermcap 288Routines to provide the user with a method of updating screens 289with reasonable optimisation. 290The 291.Xr ocurses 3 292library is compatible with the 293.Em curses 294library provided in 4.3. 295.Em libotermcap 296is the 4.3-compatible 297.Em termcap 298library, and is a hard link to 299.Em libocurses . 300See 301.Xr otermcap 3 . 302.Pp 303.It libopcodes Pq Fl lopcodes 304GNU opcode library. 305.Pp 306.It libossaudio Pq Fl lossaudio 307Provides an emulation of the OSS 308.Pq Linux 309audio interface. 310This is used only for porting programs. 311See 312.Xr ossaudio 3 . 313.Pp 314.It libpanel Pq Fl lpanel 315Terminal-independent facilities for stacked windows on 316character-cell terminals. 317Functions using the 318.Em libpanel 319library must be linked with the 320.Em libcurses 321library, i.e.\& 322.Fl lpanel lcurses . 323See 324.Xr panel 3 . 325.Pp 326.It libpcap Pq Fl lpcap 327Packet capture library. 328All packets on the network, even those destined for other hosts, 329are accessible through this library. 330See 331.Xr pcap 3 . 332.Pp 333.It libperl Pq Fl lperl 334Support routines for 335.Xr perl 1 . 336.Pp 337.It libpthread Pq Fl pthread 338.St -p1003.1-01 339threads API and thread scheduler. 340Threaded applications should use 341.Fl pthread 342not 343.Fl lpthread . 344See 345.Xr pthreads 3 . 346.Pp 347.It libreadline Pq Fl lreadline 348Command line editing interface. 349See 350.Xr readline 3 . 351.Pp 352.It libresolv Pq Fl lresolv 353The 354.Xr resolver 3 355routines are included in 356.Em libc . 357This is just an empty library for legacy applications that want to link with 358.Fl lresolv . 359.Pp 360.It librpcsvc Pq Fl lrpcsvc 361Generated by 362.Xr rpcgen 1 , 363containing stub functions for many common 364.Xr rpc 3 365protocols. 366.Pp 367.It libsectok Pq Fl lsectok 368Library for communicating with ISO 7816 smartcards. 369See 370.Xr sectok 3 . 371.Pp 372.It libskey Pq Fl lskey 373Support library for the S/Key one time password 374.Pq OTP 375authentication toolkit. 376See 377.Xr skey 3 . 378.Pp 379.It libssl Pq Fl lssl 380The OpenSSL ssl library implements the Secure Sockets Layer 381.Pq SSL v2/v3 382and Transport Layer Security 383.Pq TLS \&v1 384protocols. 385See 386.Xr ssl 3 . 387.Pp 388.It libstdc++ Pq Fl lstdc++ 389GCC subroutine library for C++. 390See 391.Xr c++ 1 . 392.Pp 393.It libusbhid Pq Fl lusbhid 394Routines to extract data from USB Human Interface Devices 395.Pq HIDs . 396See 397.Xr usbhid 3 . 398.Pp 399.It libutil Pq Fl lutil 400System utility functions. 401These are currently 402.Xr check_expire 3 , 403.Xr fmt_scaled 3 , 404.Xr fparseln 3 , 405.Xr getmaxpartitions 3 , 406.Xr getrawpartition 3 , 407.Xr login 3 , 408.Xr login_fbtab 3 , 409.Xr opendev 3 , 410.Xr opendisk 3 , 411.Xr openpty 3 , 412.Xr pidfile 3 , 413.Xr pw_getconf 3 , 414.Xr pw_init 3 , 415.Xr pw_lock 3 , 416.Xr readlabelfs 3 417and 418.Xr uucplock 3 . 419.Pp 420.It libwrap Pq Fl lwrap 421TCP wrapper access control library. 422See 423.Xr hosts_access 3 424and 425.Xr rfc1413 3 . 426.Pp 427.It liby Pq Fl ly 428The library for 429.Xr yacc 1 , 430an LALR parser generator. 431.Pp 432.It libz Pq Fl lz 433General purpose data compression library. 434The functions in this library are documented in 435.Xr compress 3 . 436The data format is described in RFCs 1950 \- 1952. 437.El 438.Pp 439Platform-specific libraries: 440.Pp 441.Bl -tag -width "libkvm" -compact 442.It libalpha Pq Fl lalpha 443Alpha I/O and memory access functions. 444See 445.Xr inb 2 . 446.Pp 447.It libi386 Pq Fl li386 448i386 I/O and memory access functions. 449See 450.Xr i386_get_ioperm 2 , 451.Xr i386_set_ioperm 2 , 452.Xr i386_get_ldt 2 , 453.Xr i386_set_ldt 2 , 454.Xr i386_iopl 2 , 455and 456.Xr i386_vm86 2 . 457.El 458.Sh LIBRARY TYPES 459The system libraries are located in 460.Pa /usr/lib . 461Typically, a library will have a number of variants: 462.Bd -unfilled -offset indent 463libc.a 464libc.so.30.1 465libc_p.a 466libc_pic.a 467.Ed 468.Pp 469Libraries with an 470.Sq .a 471suffix are static. 472When a program is linked against a library, all the library code 473will be linked into the binary. 474This means the binary can be run even when the libraries are unavailable. 475However, it can be inefficient with memory usage. 476The C compiler, 477.Xr cc 1 , 478can be instructed to link statically by specifying the 479.Fl static 480flag. 481.Pp 482Libraries with a 483.Sq .so.X.Y 484suffix are dynamic libraries. 485When code is compiled dynamically, the library code that the application needs 486is not linked into the binary. 487Instead, data structures are added containing information about which dynamic 488libraries to link with. 489When the binary is executed, the run-time linker 490.Xr ld.so 1 491reads these data structures, and loads them at a virtual address using the 492.Xr mmap 2 493system call. 494.Pp 495.Sq X 496represents the major number of the library, and 497.Sq Y 498represents the minor number. 499In general, a binary will be able to use a dynamic library with a differing 500minor number, but the major numbers must match. 501In the example above, a binary linked with minor number 502.Sq 3 503would be linkable against libc.so.30.1, 504while a binary linked with major number 505.Sq 31 506would not. 507.Pp 508The advantages of dynamic libraries are that multiple instances of the same 509program can share address space, and the physical size of the binary is 510smaller. 511The disadvantage is the added complexity that comes with loading the 512libraries dynamically, and the extra time taken to load the libraries. 513Of course, if the libraries are not available, the binary will be unable 514to execute. 515The C compiler, 516.Xr cc 1 , 517can be instructed to link dynamically by specifying the 518.Fl shared 519flag, although on systems that support it, this will be the default and 520need not be specified. 521.Pp 522Libraries with a 523.Sq _p.a 524suffix are profiling libraries. 525They contain extra information suitable for analysing programs, 526such as execution speed and call counts. 527This in turn can be interpreted by utilities such as 528.Xr gprof 1 . 529The C compiler, 530.Xr cc 1 , 531can be instructed to generate profiling code, 532or to link with profiling libraries, by specifying the 533.Fl pg 534flag. 535.Pp 536Libraries with a 537.Sq _pic.a 538suffix contain position-independent code 539.Pq PIC . 540Normally, compilers produce relocatable code. 541Relocatable code needs to be modified at run-time, depending on where in 542memory it is to be run. 543PIC code does not need to be modified at run-time, but is less efficient than 544relocatable code. 545PIC code is used by shared libraries, which can make them slower. 546The C compiler, 547.Xr cc 1 , 548can be instructed to generate PIC code, 549or to link with PIC libraries, by specifying the 550.Fl fpic 551or 552.Fl fPIC 553flags. 554.Pp 555With the exception of dynamic libraries, libraries are generated using the 556.Xr ar 1 557utility. 558The libraries contain an index to the contents of the library, 559stored within the library itself. 560The index lists each symbol defined by a member of a library that is a 561relocatable object file. 562This speeds up linking to the library, and allows routines in the library 563to call each other regardless of their placement within the library. 564The index is created by 565.Xr ranlib 1 566and can be viewed using 567.Xr nm 1 . 568.Pp 569The building of PIC versions of libraries and dynamic libraries can be 570prevented by setting the variable 571.Dv NOPIC 572in 573.Pa /etc/mk.conf . 574The building of profiling versions of libraries and/or dynamic libraries can 575be prevented by setting the variable 576.Dv NOPROFILE 577in 578.Pa /etc/mk.conf . 579See 580.Xr mk.conf 5 581for more details. 582.Sh FILES 583.Bl -tag -width /usr/lib/libotermcap.a -compact 584.It Pa /usr/lib/libasn1.a 585.It Pa /usr/lib/libbfd.a 586.It Pa /usr/lib/libc.a 587.It Pa /usr/lib/libcom_err.a 588.It Pa /usr/lib/libcompat.a 589.It Pa /usr/lib/libcrypto.a 590.It Pa /usr/lib/libcurses++.a 591.It Pa /usr/lib/libcurses.a 592.It Pa /usr/lib/libdes.a 593.It Pa /usr/lib/libedit.a 594.It Pa /usr/lib/libevent.a 595.It Pa /usr/lib/libfl.a 596.It Pa /usr/lib/libform.a 597.It Pa /usr/lib/libfrtbegin.a 598.It Pa /usr/lib/libg2c.a 599.It Pa /usr/lib/libgssapi.a 600.It Pa /usr/lib/libhdb.a 601.It Pa /usr/lib/libiberty.a 602.It Pa /usr/lib/libkadm5clnt.a 603.It Pa /usr/lib/libkadm5srv.a 604.It Pa /usr/lib/libkafs.a 605.It Pa /usr/lib/libkeynote.a 606.It Pa /usr/lib/libkrb5.a 607.It Pa /usr/lib/libkvm.a 608.It Pa /usr/lib/libl.a 609.It Pa /usr/lib/libm.a 610.It Pa /usr/lib/libmenu.a 611.It Pa /usr/lib/libmmalloc.a 612.It Pa /usr/lib/libncurses.a 613.It Pa /usr/lib/libobjc.a 614.It Pa /usr/lib/libocurses.a 615.It Pa /usr/lib/libopcodes.a 616.It Pa /usr/lib/libossaudio.a 617.It Pa /usr/lib/libotermcap.a 618.It Pa /usr/lib/libpanel.a 619.It Pa /usr/lib/libpcap.a 620.It Pa /usr/lib/libperl.a 621.It Pa /usr/lib/libpthread.a 622.It Pa /usr/lib/libreadline.a 623.It Pa /usr/lib/libresolv.a 624.It Pa /usr/lib/librpcsvc.a 625.It Pa /usr/lib/libsectok.a 626.It Pa /usr/lib/libskey.a 627.It Pa /usr/lib/libssl.a 628.It Pa /usr/lib/libstdc++.a 629.It Pa /usr/lib/libtermcap.a 630.It Pa /usr/lib/libtermlib.a 631.It Pa /usr/lib/libusbhid.a 632.It Pa /usr/lib/libutil.a 633.It Pa /usr/lib/libwrap.a 634.It Pa /usr/lib/liby.a 635.It Pa /usr/lib/libz.a 636.Pp 637.It Pa /usr/lib/libalpha.a 638.It Pa /usr/lib/libi386.a 639.El 640.Sh SEE ALSO 641.Xr ar 1 , 642.Xr c++ 1 , 643.Xr cc 1 , 644.Xr g77 1 , 645.Xr gprof 1 , 646.Xr ld 1 , 647.Xr ld.so 1 , 648.Xr lex 1 , 649.Xr nm 1 , 650.Xr perl 1 , 651.Xr ranlib 1 , 652.Xr yacc 1 , 653.Xr intro 2 , 654.Xr compress 3 , 655.Xr crypto 3 , 656.Xr curses 3 , 657.Xr des_crypt 3 , 658.Xr editline 3 , 659.Xr event 3 , 660.Xr form 3 , 661.Xr hosts_access 3 , 662.Xr keynote 3 , 663.Xr kvm 3 , 664.Xr math 3 , 665.Xr menu 3 , 666.Xr ocurses 3 , 667.Xr ossaudio 3 , 668.Xr panel 3 , 669.Xr pcap 3 , 670.Xr pthreads 3 , 671.Xr readline 3 , 672.Xr resolver 3 , 673.Xr rfc1413 3 , 674.Xr rpc 3 , 675.Xr sectok 3 , 676.Xr skey 3 , 677.Xr ssl 3 , 678.Xr stdio 3 , 679.Xr termcap 3 , 680.Xr usbhid 3 , 681.Xr keynote 4 , 682.Xr mk.conf 5 683.Sh HISTORY 684An 685.Nm 686manual appeared in 687.At v7 . 688