1.\" $OpenBSD: intro.3,v 1.69 2014/11/07 12:53:36 jsing 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 7 2014 $ 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 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 libcrypto Pq Fl lcrypto 81The OpenSSL crypto library. 82Implements a range of cryptographic algorithms, 83providing such functionality as symmetric encryption, public key cryptography, 84and certificate handling. 85See 86.Xr crypto 3 . 87.Pp 88.It libcurses Pq Fl lcurses 89.It libncurses Pq Fl lncurses 90.It libncursesw Pq Fl lncursesw 91.It libtermcap Pq Fl ltermcap 92.It libtermlib Pq Fl ltermlib 93Terminal-independent screen management routines for two-dimensional 94non-bitmap display terminals. 95This implementation is 96.Dq new curses 97and is a replacement for 98.Bx 4.2 99classic curses. 100The libraries 101.Em libncurses , 102.Em libncursesw , 103.Em libtermcap , 104and 105.Em libtermlib 106are all hard links to 107.Em libcurses . 108This is for compatibility purposes only; 109new programs should link with 110.Fl lcurses . 111See 112.Xr curses 3 113and 114.Xr termcap 3 . 115.Pp 116.It libedit Pq Fl ledit 117Generic line editing and history functions, similar to those found in 118.Xr sh 1 . 119Functions using the 120.Em libedit 121library must be linked with the 122.Em libcurses 123library, i.e.\& 124.Fl ledit lcurses . 125See 126.Xr editline 3 . 127.Pp 128.It libevent Pq Fl levent 129Provides a mechanism to execute a function when a specific event on a 130file descriptor occurs or after a given time has passed. 131See 132.Xr event 3 . 133.Pp 134.It libexpat Pq Fl lexpat 135Library routines for parsing XML documents. 136.Pp 137.It libform Pq Fl lform 138.It libformw Pq Fl lformw 139Terminal-independent facilities for composing form screens on 140character-cell terminals. 141Functions using the 142.Em libform 143library must be linked with the 144.Em libcurses 145library, i.e.\& 146.Fl lform lcurses . 147.Em libformw 148is a hard link to 149.Em libform 150intended for use with 151.Em libncursesw 152wide-character functions. 153See 154.Xr form 3 . 155.Pp 156.It libfuse Pq Fl lfuse 157File system in userland library. 158See 159.Xr fuse_main 3 . 160.Pp 161.It libgcc Pq Fl lgcc 162GCC runtime support, 163including long arithmetic, propolice, 164and language independent exception support. 165Note: users do not normally have to explicitly link with this library. 166.Pp 167.It libiberty Pq Fl liberty 168Collection of subroutines missing in other operating systems, 169as well as the C++ demangler and other functions used by 170the GNU toolchain. 171.Pp 172.It libkeynote Pq Fl lkeynote 173System library for the keynote trust-management system. 174Trust-management systems provide standard, general-purpose mechanisms 175for specifying application security policies and credentials. 176Functions using the libkeynote library must be linked with the 177.Em libm 178and 179.Em libcrypto 180libraries, i.e.\& 181.Fl lkeynote lm lcrypto . 182See 183.Xr keynote 3 184and 185.Xr keynote 4 . 186.Pp 187.It libkvm Pq Fl lkvm 188Kernel memory interface library. 189Provides a uniform interface for accessing kernel virtual memory images, 190including live systems and crash dumps. 191See 192.Xr kvm 3 . 193.Pp 194.It libl Pq Fl l\&l 195.It libfl Pq Fl lfl 196The library for 197.Xr lex 1 , 198a lexical analyzer generator. 199The 200.Em libfl 201library 202is a hard link to 203.Em libl . 204.Pp 205.It libm Pq Fl lm 206Mathematical functions which comprise the C math library, 207.Em libm . 208.Pp 209.It libmenu Pq Fl lmenu 210.It libmenuw Pq Fl lmenuw 211Terminal-independent facilities for composing menu systems on 212character-cell terminals. 213Functions using the 214.Em libmenu 215library must be linked with the 216.Em libcurses 217library, i.e.\& 218.Fl lmenu lcurses . 219.Em libmenuw 220is a hard link to 221.Em libmenu 222intended for use with 223.Em libncursesw 224wide-character functions. 225See 226.Xr menu 3 . 227.Pp 228.It libobjc Pq Fl lobjc 229Library for Objective C, an object-oriented superset of ANSI C. 230Use this to compile Objective C programs. 231.Pp 232.It libocurses Pq Fl locurses 233.It libotermcap Pq Fl lotermcap 234Routines to provide the user with a method of updating screens 235with reasonable optimisation. 236The 237.Xr ocurses 3 238library is compatible with the 239.Em curses 240library provided in 4.3. 241.Em libotermcap 242is the 4.3-compatible 243.Em termcap 244library, and is a hard link to 245.Em libocurses . 246See 247.Xr otermcap 3 . 248.Pp 249.It libossaudio Pq Fl lossaudio 250Provides an emulation of the OSS 251.Pq Linux 252audio interface. 253This is used only for porting programs. 254See 255.Xr ossaudio 3 . 256.Pp 257.It libpanel Pq Fl lpanel 258.It libpanelw Pq Fl lpanelw 259Terminal-independent facilities for stacked windows on 260character-cell terminals. 261Functions using the 262.Em libpanel 263library must be linked with the 264.Em libcurses 265library, i.e.\& 266.Fl lpanel lcurses . 267.Em libpanelw 268is a hard link to 269.Em libpanel 270intended for use with 271.Em libncursesw 272wide-charcter functions. 273See 274.Xr panel 3 . 275.Pp 276.It libpcap Pq Fl lpcap 277Packet capture library. 278All packets on the network, even those destined for other hosts, 279are accessible through this library. 280See 281.Xr pcap 3 . 282.Pp 283.It libperl Pq Fl lperl 284Support routines for 285.Xr perl 1 . 286.Pp 287.It libpthread Pq Fl lpthread 288.St -p1003.1-2001 289threads API. 290See 291.Xr pthreads 3 . 292.Pp 293.It libreadline Pq Fl lreadline 294Command line editing interface. 295See 296.Xr readline 3 . 297.Pp 298.It librpcsvc Pq Fl lrpcsvc 299Generated by 300.Xr rpcgen 1 , 301containing stub functions for many common 302.Xr rpc 3 303protocols. 304.Pp 305.It libskey Pq Fl lskey 306Support library for the S/Key one time password 307.Pq OTP 308authentication toolkit. 309See 310.Xr skey 3 . 311.Pp 312.It libsndio Pq Fl lsndio 313Library for 314.Xr audio 4 315hardware and the 316.Xr aucat 1 317audio server. 318See 319.Xr sio_open 3 . 320.Pp 321.It libsqlite3 Pq Fl lsqlite3 322SQL database library. 323See 324.Xr sqlite3 1 . 325.Pp 326.It libssl Pq Fl lssl 327The OpenSSL ssl library implements the Secure Sockets Layer 328.Pq SSL v3 329and Transport Layer Security 330.Pq TLS v1 331protocols. 332See 333.Xr ssl 3 . 334.Pp 335.It libstdc++ Pq Fl lstdc++ 336GCC subroutine library for C++. 337See 338.Xr c++ 1 . 339Note: users do not normally have to explicitly link with this library. 340.Pp 341.It libsupc++ Pq Fl lsupc++ 342C++ core language support 343(exceptions, new, typeinfo). 344Note: users do not normally have to explicitly link with this library. 345.Pp 346.It libtls Pq Fl tls 347A Transport Layer Security library with a clean and easy to use interface. 348See 349.Xr tls_init 3 . 350.Pp 351.It libusbhid Pq Fl lusbhid 352Routines to extract data from USB Human Interface Devices 353.Pq HIDs . 354See 355.Xr usbhid 3 . 356.Pp 357.It libutil Pq Fl lutil 358System utility functions. 359These are currently 360.Xr check_expire 3 , 361.Xr fmt_scaled 3 , 362.Xr fparseln 3 , 363.Xr getmaxpartitions 3 , 364.Xr getrawpartition 3 , 365.Xr imsg_init 3 , 366.Xr login 3 , 367.Xr login_fbtab 3 , 368.Xr ohash_init 3 , 369.Xr ohash_interval 3 , 370.Xr opendev 3 , 371.Xr opendisk 3 , 372.Xr openpty 3 , 373.Xr pidfile 3 , 374.Xr pkcs5_pbkdf2 3 , 375.Xr pw_init 3 , 376.Xr pw_lock 3 , 377.Xr readlabelfs 3 378and 379.Xr uucplock 3 . 380.Pp 381.It liby Pq Fl ly 382The library for 383.Xr yacc 1 , 384an LALR parser generator. 385.Pp 386.It libz Pq Fl lz 387General purpose data compression library. 388The functions in this library are documented in 389.Xr compress 3 . 390The data format is described in RFCs 1950 \- 1952. 391.El 392.Pp 393Platform-specific libraries: 394.Bl -tag -width "libkvm" 395.It libalpha Pq Fl lalpha 396Alpha I/O and memory access functions. 397See 398.Xr inb 2 . 399.It libamd64 Pq Fl lamd64 400AMD64 I/O and memory access functions. 401See 402.Xr amd64_iopl 2 . 403.It libarm Pq Fl larm 404ARM I/O and memory access functions. 405See 406.Xr arm_drain_writebuf 2 407and 408.Xr arm_sync_icache 2 . 409.It libi386 Pq Fl li386 410i386 I/O and memory access functions. 411See 412.Xr i386_get_ioperm 2 , 413.Xr i386_get_ldt 2 , 414.Xr i386_iopl 2 , 415and 416.Xr i386_vm86 2 . 417.El 418.Sh LIBRARY TYPES 419The system libraries are located in 420.Pa /usr/lib . 421Typically, a library will have a number of variants: 422.Bd -unfilled -offset indent 423libc.a 424libc_p.a 425libc.so.30.1 426.Ed 427.Pp 428Libraries with an 429.Sq .a 430suffix are static. 431When a program is linked against a library, all the library code 432will be linked into the binary. 433This means the binary can be run even when the libraries are unavailable. 434However, it can be inefficient with memory usage. 435The C compiler, 436.Xr cc 1 , 437can be instructed to link statically by specifying the 438.Fl static 439flag. 440.Pp 441Libraries with a 442.Sq _p.a 443suffix are profiling libraries. 444They contain extra information suitable for analysing programs, 445such as execution speed and call counts. 446This in turn can be interpreted by utilities such as 447.Xr gprof 1 . 448The C compiler, 449.Xr cc 1 , 450can be instructed to generate profiling code, 451or to link with profiling libraries, by specifying the 452.Fl pg 453flag. 454.Pp 455Libraries with a 456.Sq .so.X.Y 457suffix are dynamic libraries. 458When code is compiled dynamically, the library code that the application needs 459is not linked into the binary. 460Instead, data structures are added containing information about which dynamic 461libraries to link with. 462When the binary is executed, the run-time linker 463.Xr ld.so 1 464reads these data structures, and loads them at a virtual address using the 465.Xr mmap 2 466system call. 467.Pp 468.Sq X 469represents the major number of the library, and 470.Sq Y 471represents the minor number. 472In general, a binary will be able to use a dynamic library with a differing 473minor number, but the major numbers must match. 474In the example above, a binary linked with minor number 475.Sq 3 476would be linkable against libc.so.30.1, 477while a binary linked with major number 478.Sq 31 479would not. 480.Pp 481The advantages of dynamic libraries are that multiple instances of the same 482program can share address space, and the physical size of the binary is 483smaller. 484The disadvantage is the added complexity that comes with loading the 485libraries dynamically, and the extra time taken to load the libraries. 486Of course, if the libraries are not available, the binary will be unable 487to execute. 488The C compiler, 489.Xr cc 1 , 490can be instructed to link dynamically by specifying the 491.Fl shared 492flag, although on systems that support it, this will be the default and 493need not be specified. 494.Pp 495Shared libraries, as well as static libraries on architectures which produce 496position-independent executables 497.Pq PIEs 498by default, contain position-independent code 499.Pq PIC . 500Normally, compilers produce relocatable code. 501Relocatable code needs to be modified at run-time, depending on where in 502memory it is to be run. 503PIC code does not need to be modified at run-time, but is less efficient than 504relocatable code. 505The C compiler, 506.Xr cc 1 , 507can be instructed to generate PIC code by specifying the 508.Fl fpic 509or 510.Fl fPIC 511flags. 512.Pp 513With the exception of dynamic libraries, libraries are generated using the 514.Xr ar 1 515utility. 516The libraries contain an index to the contents of the library, 517stored within the library itself. 518The index lists each symbol defined by a member of a library that is a 519relocatable object file. 520This speeds up linking to the library, and allows routines in the library 521to call each other regardless of their placement within the library. 522The index is created by 523.Xr ranlib 1 524and can be viewed using 525.Xr nm 1 . 526.Pp 527The building of dynamic libraries can be prevented by setting the variable 528.Dv NOPIC 529in 530.Pa /etc/mk.conf . 531The building of profiling versions of libraries can 532be prevented by setting the variable 533.Dv NOPROFILE 534in 535.Pa /etc/mk.conf . 536See 537.Xr mk.conf 5 538for more details. 539.Sh SEE ALSO 540.Xr ar 1 , 541.Xr cc 1 , 542.Xr gcc-local 1 , 543.Xr gprof 1 , 544.Xr ld 1 , 545.Xr ld.so 1 , 546.Xr nm 1 , 547.Xr ranlib 1 , 548.Xr mk.conf 5 549.Sh HISTORY 550An 551.Nm 552manual appeared in 553.At v7 . 554