1.\" $OpenBSD: intro.3,v 1.23 2004/03/12 17:42:21 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-2001 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 libamd64 Pq Fl lamd64 448AMD64 I/O and memory access functions. 449See 450.Xr amd64_get_ioperm 2 , 451.Xr amd64_get_ldt 2 , 452.Xr amd64_get_mtrr 2 , 453.Xr amd64_iopl 2 , 454and 455.Xr amd64_vm86 2 . 456.Pp 457.It libi386 Pq Fl li386 458i386 I/O and memory access functions. 459See 460.Xr i386_get_ioperm 2 , 461.Xr i386_get_ldt 2 , 462.Xr i386_iopl 2 , 463and 464.Xr i386_vm86 2 . 465.El 466.Sh LIBRARY TYPES 467The system libraries are located in 468.Pa /usr/lib . 469Typically, a library will have a number of variants: 470.Bd -unfilled -offset indent 471libc.a 472libc.so.30.1 473libc_p.a 474libc_pic.a 475.Ed 476.Pp 477Libraries with an 478.Sq .a 479suffix are static. 480When a program is linked against a library, all the library code 481will be linked into the binary. 482This means the binary can be run even when the libraries are unavailable. 483However, it can be inefficient with memory usage. 484The C compiler, 485.Xr cc 1 , 486can be instructed to link statically by specifying the 487.Fl static 488flag. 489.Pp 490Libraries with a 491.Sq .so.X.Y 492suffix are dynamic libraries. 493When code is compiled dynamically, the library code that the application needs 494is not linked into the binary. 495Instead, data structures are added containing information about which dynamic 496libraries to link with. 497When the binary is executed, the run-time linker 498.Xr ld.so 1 499reads these data structures, and loads them at a virtual address using the 500.Xr mmap 2 501system call. 502.Pp 503.Sq X 504represents the major number of the library, and 505.Sq Y 506represents the minor number. 507In general, a binary will be able to use a dynamic library with a differing 508minor number, but the major numbers must match. 509In the example above, a binary linked with minor number 510.Sq 3 511would be linkable against libc.so.30.1, 512while a binary linked with major number 513.Sq 31 514would not. 515.Pp 516The advantages of dynamic libraries are that multiple instances of the same 517program can share address space, and the physical size of the binary is 518smaller. 519The disadvantage is the added complexity that comes with loading the 520libraries dynamically, and the extra time taken to load the libraries. 521Of course, if the libraries are not available, the binary will be unable 522to execute. 523The C compiler, 524.Xr cc 1 , 525can be instructed to link dynamically by specifying the 526.Fl shared 527flag, although on systems that support it, this will be the default and 528need not be specified. 529.Pp 530Libraries with a 531.Sq _p.a 532suffix are profiling libraries. 533They contain extra information suitable for analysing programs, 534such as execution speed and call counts. 535This in turn can be interpreted by utilities such as 536.Xr gprof 1 . 537The C compiler, 538.Xr cc 1 , 539can be instructed to generate profiling code, 540or to link with profiling libraries, by specifying the 541.Fl pg 542flag. 543.Pp 544Libraries with a 545.Sq _pic.a 546suffix contain position-independent code 547.Pq PIC . 548Normally, compilers produce relocatable code. 549Relocatable code needs to be modified at run-time, depending on where in 550memory it is to be run. 551PIC code does not need to be modified at run-time, but is less efficient than 552relocatable code. 553PIC code is used by shared libraries, which can make them slower. 554The C compiler, 555.Xr cc 1 , 556can be instructed to generate PIC code, 557or to link with PIC libraries, by specifying the 558.Fl fpic 559or 560.Fl fPIC 561flags. 562.Pp 563With the exception of dynamic libraries, libraries are generated using the 564.Xr ar 1 565utility. 566The libraries contain an index to the contents of the library, 567stored within the library itself. 568The index lists each symbol defined by a member of a library that is a 569relocatable object file. 570This speeds up linking to the library, and allows routines in the library 571to call each other regardless of their placement within the library. 572The index is created by 573.Xr ranlib 1 574and can be viewed using 575.Xr nm 1 . 576.Pp 577The building of PIC versions of libraries and dynamic libraries can be 578prevented by setting the variable 579.Dv NOPIC 580in 581.Pa /etc/mk.conf . 582The building of profiling versions of libraries and/or dynamic libraries can 583be prevented by setting the variable 584.Dv NOPROFILE 585in 586.Pa /etc/mk.conf . 587See 588.Xr mk.conf 5 589for more details. 590.Sh FILES 591.Bl -tag -width /usr/lib/libotermcap.a -compact 592.It Pa /usr/lib/libasn1.a 593.It Pa /usr/lib/libbfd.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/libcurses.a 600.It Pa /usr/lib/libdes.a 601.It Pa /usr/lib/libedit.a 602.It Pa /usr/lib/libevent.a 603.It Pa /usr/lib/libfl.a 604.It Pa /usr/lib/libform.a 605.It Pa /usr/lib/libfrtbegin.a 606.It Pa /usr/lib/libg2c.a 607.It Pa /usr/lib/libgssapi.a 608.It Pa /usr/lib/libhdb.a 609.It Pa /usr/lib/libiberty.a 610.It Pa /usr/lib/libkadm5clnt.a 611.It Pa /usr/lib/libkadm5srv.a 612.It Pa /usr/lib/libkafs.a 613.It Pa /usr/lib/libkeynote.a 614.It Pa /usr/lib/libkrb5.a 615.It Pa /usr/lib/libkvm.a 616.It Pa /usr/lib/libl.a 617.It Pa /usr/lib/libm.a 618.It Pa /usr/lib/libmenu.a 619.It Pa /usr/lib/libmmalloc.a 620.It Pa /usr/lib/libncurses.a 621.It Pa /usr/lib/libobjc.a 622.It Pa /usr/lib/libocurses.a 623.It Pa /usr/lib/libopcodes.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/libpcap.a 628.It Pa /usr/lib/libperl.a 629.It Pa /usr/lib/libpthread.a 630.It Pa /usr/lib/libreadline.a 631.It Pa /usr/lib/libresolv.a 632.It Pa /usr/lib/librpcsvc.a 633.It Pa /usr/lib/libsectok.a 634.It Pa /usr/lib/libskey.a 635.It Pa /usr/lib/libssl.a 636.It Pa /usr/lib/libstdc++.a 637.It Pa /usr/lib/libtermcap.a 638.It Pa /usr/lib/libtermlib.a 639.It Pa /usr/lib/libusbhid.a 640.It Pa /usr/lib/libutil.a 641.It Pa /usr/lib/libwrap.a 642.It Pa /usr/lib/liby.a 643.It Pa /usr/lib/libz.a 644.Pp 645.It Pa /usr/lib/libalpha.a 646.It Pa /usr/lib/libamd64.a 647.It Pa /usr/lib/libi386.a 648.El 649.Sh SEE ALSO 650.Xr ar 1 , 651.Xr c++ 1 , 652.Xr cc 1 , 653.Xr g77 1 , 654.Xr gcc-local 1 , 655.Xr gprof 1 , 656.Xr ld 1 , 657.Xr ld.so 1 , 658.Xr lex 1 , 659.Xr nm 1 , 660.Xr perl 1 , 661.Xr ranlib 1 , 662.Xr yacc 1 , 663.Xr intro 2 , 664.Xr compress 3 , 665.Xr crypto 3 , 666.Xr curses 3 , 667.Xr des_crypt 3 , 668.Xr editline 3 , 669.Xr event 3 , 670.Xr form 3 , 671.Xr hosts_access 3 , 672.Xr keynote 3 , 673.Xr kvm 3 , 674.Xr math 3 , 675.Xr menu 3 , 676.Xr ocurses 3 , 677.Xr ossaudio 3 , 678.Xr panel 3 , 679.Xr pcap 3 , 680.Xr pthreads 3 , 681.Xr readline 3 , 682.Xr resolver 3 , 683.Xr rfc1413 3 , 684.Xr rpc 3 , 685.Xr sectok 3 , 686.Xr skey 3 , 687.Xr ssl 3 , 688.Xr stdio 3 , 689.Xr termcap 3 , 690.Xr usbhid 3 , 691.Xr keynote 4 , 692.Xr mk.conf 5 693.Sh HISTORY 694An 695.Nm 696manual appeared in 697.At v7 . 698