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