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