1.\" $OpenBSD: intro.3,v 1.75 2016/03/24 08:30:58 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: March 24 2016 $ 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 libossaudio Pq Fl lossaudio 233Provides an emulation of the OSS 234.Pq Linux 235audio interface. 236This is used only for porting programs. 237See 238.Xr ossaudio 3 . 239.Pp 240.It libpanel Pq Fl lpanel 241.It libpanelw Pq Fl lpanelw 242Terminal-independent facilities for stacked windows on 243character-cell terminals. 244Functions using the 245.Em libpanel 246library must be linked with the 247.Em libcurses 248library, i.e.\& 249.Fl lpanel lcurses . 250.Em libpanelw 251is a hard link to 252.Em libpanel 253intended for use with 254.Em libncursesw 255wide-character functions. 256See 257.Xr panel 3 . 258.Pp 259.It libpcap Pq Fl lpcap 260Packet capture library. 261All packets on the network, even those destined for other hosts, 262are accessible through this library. 263See 264.Xr pcap 3 . 265.Pp 266.It libperl Pq Fl lperl 267Support routines for 268.Xr perl 1 . 269.Pp 270.It libpthread Pq Fl lpthread 271.St -p1003.1-2001 272threads API. 273See 274.Xr pthreads 3 . 275.Pp 276.It libradius Pq Fl lradius 277Support routines for the RADIUS library. 278See 279.Xr radius_new_request_packet 3 . 280.Pp 281.It libreadline Pq Fl lreadline 282Command line editing interface. 283See 284.Xr readline 3 . 285.Pp 286.It librpcsvc Pq Fl lrpcsvc 287Generated by 288.Xr rpcgen 1 , 289containing stub functions for many common 290.Xr rpc 3 291protocols. 292.Pp 293.It libskey Pq Fl lskey 294Support library for the S/Key one time password 295.Pq OTP 296authentication toolkit. 297See 298.Xr skey 3 . 299.Pp 300.It libsndio Pq Fl lsndio 301Library for 302.Xr audio 4 303hardware and the 304.Xr aucat 1 305audio server. 306See 307.Xr sio_open 3 . 308.Pp 309.It libsqlite3 Pq Fl lsqlite3 310SQL database library. 311See 312.Xr sqlite3 1 . 313.Pp 314.It libssl Pq Fl lssl 315The OpenSSL ssl library implements the Secure Sockets Layer 316.Pq SSL v3 317and Transport Layer Security 318.Pq TLS v1 319protocols. 320See 321.Xr ssl 3 . 322.Pp 323.It libstdc++ Pq Fl lstdc++ 324GCC subroutine library for C++. 325See 326.Xr c++ 1 . 327Note: users do not normally have to explicitly link with this library. 328.Pp 329.It libsupc++ Pq Fl lsupc++ 330C++ core language support 331(exceptions, new, typeinfo). 332Note: users do not normally have to explicitly link with this library. 333.Pp 334.It libtls Pq Fl tls 335A Transport Layer Security library with a clean and easy to use interface. 336See 337.Xr tls_init 3 . 338.Pp 339.It libusbhid Pq Fl lusbhid 340Routines to extract data from USB Human Interface Devices 341.Pq HIDs . 342See 343.Xr usbhid 3 . 344.Pp 345.It libutil Pq Fl lutil 346System utility functions. 347These are currently 348.Xr check_expire 3 , 349.Xr fmt_scaled 3 , 350.Xr fparseln 3 , 351.Xr getmaxpartitions 3 , 352.Xr getrawpartition 3 , 353.Xr imsg_init 3 , 354.Xr login 3 , 355.Xr login_fbtab 3 , 356.Xr ohash_init 3 , 357.Xr ohash_interval 3 , 358.Xr opendev 3 , 359.Xr opendisk 3 , 360.Xr openpty 3 , 361.Xr pidfile 3 , 362.Xr pkcs5_pbkdf2 3 , 363.Xr pw_init 3 , 364.Xr pw_lock 3 , 365.Xr readlabelfs 3 366and 367.Xr uucplock 3 . 368.Pp 369.It liby Pq Fl ly 370The library for 371.Xr yacc 1 , 372an LALR parser generator. 373.Pp 374.It libz Pq Fl lz 375General purpose data compression library. 376The functions in this library are documented in 377.Xr compress 3 . 378The data format is described in RFCs 1950 \- 1952. 379.El 380.Pp 381Platform-specific libraries: 382.Bl -tag -width "libkvm" 383.It libalpha Pq Fl lalpha 384Alpha I/O and memory access functions. 385See 386.Xr inb 2 . 387.It libamd64 Pq Fl lamd64 388AMD64 I/O and memory access functions. 389See 390.Xr amd64_iopl 2 . 391.It libarm Pq Fl larm 392ARM I/O and memory access functions. 393See 394.Xr arm_drain_writebuf 2 395and 396.Xr arm_sync_icache 2 . 397.It libi386 Pq Fl li386 398i386 I/O and memory access functions. 399See 400.Xr i386_iopl 2 401and 402.Xr i386_vm86 2 . 403.El 404.Sh LIBRARY TYPES 405The system libraries are located in 406.Pa /usr/lib . 407Typically, a library will have a number of variants: 408.Bd -unfilled -offset indent 409libc.a 410libc_p.a 411libc.so.30.1 412.Ed 413.Pp 414Libraries with an 415.Sq .a 416suffix are static. 417When a program is linked against a library, all the library code 418will be linked into the binary. 419This means the binary can be run even when the libraries are unavailable. 420However, it can be inefficient with memory usage. 421The C compiler, 422.Xr cc 1 , 423can be instructed to link statically by specifying the 424.Fl static 425flag. 426.Pp 427Libraries with a 428.Sq _p.a 429suffix are profiling libraries. 430They contain extra information suitable for analysing programs, 431such as execution speed and call counts. 432This in turn can be interpreted by utilities such as 433.Xr gprof 1 . 434The C compiler, 435.Xr cc 1 , 436can be instructed to generate profiling code, 437or to link with profiling libraries, by specifying the 438.Fl pg 439flag. 440.Pp 441Libraries with a 442.Sq .so.X.Y 443suffix are dynamic libraries. 444When code is compiled dynamically, the library code that the application needs 445is not linked into the binary. 446Instead, data structures are added containing information about which dynamic 447libraries to link with. 448When the binary is executed, the run-time linker 449.Xr ld.so 1 450reads these data structures, and loads them at a virtual address using the 451.Xr mmap 2 452system call. 453.Pp 454.Sq X 455represents the major number of the library, and 456.Sq Y 457represents the minor number. 458In general, a binary will be able to use a dynamic library with a differing 459minor number, but the major numbers must match. 460In the example above, a binary linked with minor number 461.Sq 3 462would be linkable against libc.so.30.1, 463while a binary linked with major number 464.Sq 31 465would not. 466.Pp 467The advantages of dynamic libraries are that multiple instances of the same 468program can share address space, and the physical size of the binary is 469smaller. 470The disadvantage is the added complexity that comes with loading the 471libraries dynamically, and the extra time taken to load the libraries. 472Of course, if the libraries are not available, the binary will be unable 473to execute. 474The C compiler, 475.Xr cc 1 , 476can be instructed to link dynamically by specifying the 477.Fl shared 478flag, although on systems that support it, this will be the default and 479need not be specified. 480.Pp 481Shared libraries, as well as static libraries on architectures which produce 482position-independent executables 483.Pq PIEs 484by default, contain position-independent code 485.Pq PIC . 486Normally, compilers produce relocatable code. 487Relocatable code needs to be modified at run-time, depending on where in 488memory it is to be run. 489PIC code does not need to be modified at run-time, but is less efficient than 490relocatable code. 491The C compiler, 492.Xr cc 1 , 493can be instructed to generate PIC code by specifying the 494.Fl fpic 495or 496.Fl fPIC 497flags. 498.Pp 499With the exception of dynamic libraries, libraries are generated using the 500.Xr ar 1 501utility. 502The libraries contain an index to the contents of the library, 503stored within the library itself. 504The index lists each symbol defined by a member of a library that is a 505relocatable object file. 506This speeds up linking to the library, and allows routines in the library 507to call each other regardless of their placement within the library. 508The index is created by 509.Xr ranlib 1 510and can be viewed using 511.Xr nm 1 . 512.Pp 513The building of dynamic libraries can be prevented by setting the variable 514.Dv NOPIC 515in 516.Pa /etc/mk.conf . 517The building of profiling versions of libraries can 518be prevented by setting the variable 519.Dv NOPROFILE 520in 521.Pa /etc/mk.conf . 522See 523.Xr mk.conf 5 524for more details. 525.Sh SEE ALSO 526.Xr ar 1 , 527.Xr cc 1 , 528.Xr gcc-local 1 , 529.Xr gprof 1 , 530.Xr ld 1 , 531.Xr ld.so 1 , 532.Xr nm 1 , 533.Xr ranlib 1 , 534.Xr mk.conf 5 535.Sh HISTORY 536An 537.Nm 538manual appeared in 539.At v7 . 540