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