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