Static library

In computer science, a static library or statically linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.[1] This executable and the process of compiling it are both known as a static build of the program. Historically, libraries could only be static. Static libraries are either merged with other static libraries and object files during building/linking to form a single executable or loaded at run-time into the address space of their corresponding executable at a static memory offset determined at compile-time/link-time.

Advantages and disadvantages

There are several advantages to statically linking libraries with an executable instead of dynamically linking them. The most significant advantage is that the application can be certain that all its libraries are present and that they are the correct version. This avoids dependency problems, known colloquially as DLL Hell or more generally dependency hell. Static linking can also allow the application to be contained in a single executable file, simplifying distribution and installation.

With static linking, it is enough to include those parts of the library that are directly and indirectly referenced by the target executable (or target library). With dynamic libraries, the entire library is loaded, as it is not known in advance which functions will be invoked by applications. Whether this advantage is significant in practice depends on the structure of the library.

In static linking, the size of the executable becomes greater than in dynamic linking, as the library code is stored within the executable rather than in separate files. But if library files are counted as part of the application then the total size will be similar, or even smaller if the compiler eliminates the unused symbols.

Environment specific

On Microsoft Windows it is common to include the library files an application needs with the application.[2] On Unix-like systems this is less common as package management systems can be used to ensure the correct library files are available. This allows the library files to be shared between many applications leading to space savings. It also allows the library to be updated to fix bugs and security flaws without updating the applications that use the library. In practice, many executables (especially those targeting Microsoft Windows) use both static and dynamic libraries.

Linking and loading

Any static library function can call a function or procedure in another static library. The linker and loader handle this the same way as for kinds of other object files. Static library files may be linked at run time by a linking loader (e.g., the X11 module loader). However, whether such a process can be called static linking is controversial.

Creating static libraries in C/C++

Static libraries can be easily created in C or in C++. These two languages provide storage-class specifiers for indicating external or internal linkage, in addition to providing other features. To create such a library, the exported functions/procedures and other objects variables must be specified for external linkage (i.e. by not using the C static keyword). Static library filenames usually have ".a" extension on Unix-like systems[1] and ".lib" extension on Microsoft Windows.

For example, on a Unix-like system, to create an archive named libclass.a from files class1.o, class2.o, class3.o, the following command would be used:[1]

ar rcs libclass.a class1.o class2.o class3.o

to compile a program that depends on class1.o, class2.o, and class3.o, one could do:

cc main.c libclass.a

or (if libclass.a is placed in standard library path, like /usr/local/lib)

cc main.c -lclass

or (during linking)

ld ... main.o -lclass ...

instead of:

cc main.c class1.o class2.o class3.o

See also

References

  1. ^ a b c "Static Libraries". TLDP. Retrieved 3 October 2013.
  2. ^ Anderson, Rick (2000-01-11). "The End of DLL Hell". microsoft.com. Archived from the original on 2001-06-05. Retrieved 2013-08-31. Private DLLs are DLLs that are installed with a specific application and used only by that application.

Read other articles:

Katedral Santa FeKatedral Basilika Santo Fransiskus dari AsssiInggris: Cathedral Basilica of Saint Francis of Assisicode: en is deprecated Katedral Basilika Santo Fransiskus dari AsssiLokasiSanta Fe, New MexicoNegaraAmerika SerikatDenominasiGereja Katolik RomaSitus webwww.cbsfa.orgSejarahDidirikan1714 (paroki)DedikasiSanto Fransiskus dari AsssiTanggal dedikasi1887ArsitekturStatusKatedral/ParokiStatus fungsionalAktifGayaNeo-RomanesqueDibangun1869-1887AdministrasiKeuskupan AgungKeuskupan Agung ...

 

Pour les articles homonymes, voir Nessebar. Nessebar НесебърΜεσημβρία Héraldique Administration Pays Bulgarie District Municipalité de Nessebar Oblast Bourgas (oblast) Code postal 8230 Démographie Population 12 036 hab. (2022) Géographie Coordonnées 42° 39′ 33″ nord, 27° 43′ 42″ est Altitude 5 m Divers https://www.nesebar.bg/ Localisation Géolocalisation sur la carte : Bulgarie Nessebar modifier  Nessebar ...

 

City in Minnesota, United States City in Minnesota, United StatesSt. PeterCityDowntown St. PeterMotto: Where History & Progress MeetLocation of the city of St. Peterwithin Nicollet Countyin the state of MinnesotaSt. PeterShow map of MinnesotaSt. PeterShow map of the United StatesCoordinates: 44°19′46″N 93°57′57″W / 44.32944°N 93.96583°W / 44.32944; -93.96583CountryUnited StatesStateMinnesotaCountyNicolletFounded1853Incorporated1873Government �...

Lowest tier of administration within a sovereign state This article possibly contains original research. Please improve it by verifying the claims made and adding inline citations. Statements consisting only of original research should be removed. (January 2011) (Learn how and when to remove this message) Part of the Politics seriesBasic forms of government List of forms of government List of countries by system of government Source of power Democracy (rule by many) Demarchy Direct Liberal Re...

 

2015 studio album by The Maccabees Marks to Prove ItStudio album by The MaccabeesReleased31 July 2015RecordedSeptember 2013 - February 2015StudioElephant Studios[1]Genre Indie rock art rock Length41:17Label Fiction Communion Producer Hugo White The Maccabees , Laurie Latham[2] The Maccabees chronology Given to the Wild(2012) Marks to Prove It(2015) Singles from Marks to Prove It Marks to Prove ItReleased: 11 May 2015 Something Like HappinessReleased: 1 June 2015 Spit It Ou...

 

Italian cycling team (1993–2002) MapeiPaolo Bettini in a Mapei jersey in 2001Team informationUCI codeMAPRegisteredItaly (1993–1997)Belgium (1998–2002)Founded1993 (1993)Disbanded2002 (2002)Discipline(s)RoadBicyclesViner (1993)Colnago (1994–2002)Key personnelTeam manager(s)Giuseppe Saronni (1997–1998)Patrick Lefevere (1999–2000)Alvaro Crespi (2000–2002)Team name history199319941995–199719981999–2002MapeiMapei–ClasMapei–GBMapei–BricobiMapei–Quick Step Mapei wa...

عسكريالتسمية للأنثى عسكرية فرع من محاربموظفشؤون عسكرية تعديل - تعديل مصدري - تعديل ويكي بيانات الأفراد العسكريون هم أعضاء في القوات المسلحة للدولة. أدوارهم، ورواتبهم، ومستلزماتهم تختلف حسب الجناح العسكري التابعين له (الجيش، البحرية، المارينز، سلاح الجو، وأحيانا خفر السو...

 

Football clubG.S. Megas Alexandros ThessalonikiFull nameGymnastikos Syllogos Megas Alexandros(Gymnastic Club Alexander the Great)Nickname(s)KaminikiaFounded1923WebsiteClub website Home colours G.S. Megas Alexandros Thessaloniki (Greek: Γ.Σ. Μέγας Αλέξανδρος) is a multi-sport club that is located in the district of Dépôt, in the city of Thessaloniki, Greece. The club's full name is Gymnastikos Syllogos Megas Alexandros (Γυμναστικός Σύλλογος Μέγας Α�...

 

American basketball player and coach Andy PhillipThe Illio, 1947Personal informationBorn(1922-03-07)March 7, 1922Granite City, Illinois, U.S.DiedApril 29, 2001(2001-04-29) (aged 79)Rancho Mirage, California, U.S.NationalityAmericanListed height6 ft 2 in (1.88 m)Listed weight195 lb (88 kg)Career informationHigh schoolGranite City (Granite City, Illinois)CollegeIllinois (1941–1943, 1946–1947)NBA draft1947: 5th round, 47th overall pickSelected by the Chicago Sta...

1904 Arkansas gubernatorial election ← 1902 5 September 1904 1906 →   Nominee Jeff Davis Harry H. Myers Party Democratic Republican Popular vote 90,263 53,898 Percentage 60.97% 36.41% Governor before election Jeff Davis Democratic Elected Governor Jeff Davis Democratic Elections in Arkansas Federal government Presidential elections 1836 1840 1844 1848 1852 1856 1860 1868 1872 1876 1880 1884 1888 1892 1896 1900 1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1...

 

PowerDirectorسايبر لينك cyberlinkمعلومات عامةالتأسيس 1996النوع برامج تحرير الفيديو موقع الويب tw.cyberlink.com… المنظومة الاقتصاديةالصناعة برمجيات حاسوبالمنتجات Video editing software DVD playback software Disc and data burning software Digital home softwareDVD authoring and optical disc authoring softwareتعديل - تعديل مصدري - تعديل ويكي بيانات PowerDirector �...

 

Benzodiazepine medication LormetazepamClinical dataTrade namesNoctamid, Loramet, othersOther namesMethyllorazepam; Methyl-lorazepam; N-Methyllorazepam; Ro 5-5516AHFS/Drugs.comInternational Drug NamesPregnancycategory D Routes ofadministrationOral, intravenous[1]Drug classBenzodiazepineATC codeN05CD06 (WHO) Legal statusLegal status BR: Class B1 (Psychoactive drugs)[2] CA: Schedule IV DE: Prescription only (Anlage III for higher doses) US: Schedule ...

本條目存在以下問題,請協助改善本條目或在討論頁針對議題發表看法。 此條目需要編修,以確保文法、用詞、语气、格式、標點等使用恰当。 (2013年8月6日)請按照校對指引,幫助编辑這個條目。(幫助、討論) 此條目剧情、虛構用語或人物介紹过长过细,需清理无关故事主轴的细节、用語和角色介紹。 (2020年10月6日)劇情、用語和人物介紹都只是用於了解故事主軸,輔助�...

 

Allergic eye disease التهاب الملتحمة التحسسي مع تورم ملتحميالتهاب الملتحمة التحسسي مع تورم ملتحمي معلومات عامة الاختصاص طب العيون،  وعلم الأرجيات  من أنواع حساسية  تعديل مصدري - تعديل   الحساسية الربيعية الحساسية الربيعية أو التهاب الملتحمة التحسسي.[1][2][3] هو...

 

René d'AlençonPortrait posthume issu d'un recueilTitre de noblesseDucBiographieNaissance 1454Lieu inconnuDécès 1er novembre 1492AlençonActivité Chef militaireFamille Maison de ValoisPère Jean II d'AlençonMère Marie d'ArmagnacConjoints Marguerite de Lorraine (à partir de 1488)Marguerite d'Harcourt (d)Enfants Charles IV d'AlençonFrançoise d'AlençonAnne d'AlençonBlasonmodifier - modifier le code - modifier Wikidata René de Valois, né en 1454, mort à Alençon le 1er nov...

Person undergoing medical treatment For the state of being, see Patience. For other uses, see Patient (disambiguation). Part of a series on PatientsPatients Concepts Doctor-patient relationship Medical ethics Patient participation Patient-reported outcome Patient safety Consent Informed consent Adherence Informal coercion Motivational interviewing Involuntary treatment Rights Patients' rights Pregnant patients' rights Disability rights movement Patient's Charter Medical law Approaches Patient...

 

Lithuanian goddess ŽemynaEarthConsortPerkūnas or Praamžius Part of a series onBaltic religion Mythology Prussian Lithuanian Latvian Indo-European Deities Panbaltic Perkūnas Velnias Dievas Saulė Mėnulis Prussian Patollo Peckols Potrimpo Swayxtix Autrimps Aušlavis Bardoayts Kurka Pilnytis Puszajtis Latvian Ūsiņš Ceroklis Jumis Auseklis Laima Dēkla Kārta Lauma Māra Mahte Lithuanian Gabija Žemyna Laima Medeina/Žvorūna Laumė/Ragana Aušrinė Bangpūtys/Vėjopatis Rūgutis Miscella...

 

Theoretical physicist (1939–2023) In this name that follows Eastern Slavic naming customs, the patronymic is Wladimir and the family name is Jackiw. Roman JackiwРоман ЯцківJackiw in 2013Born(1939-11-08)8 November 1939Lubliniec, General Government (now Poland)Died14 June 2023(2023-06-14) (aged 83)Alma materCornellSwarthmoreKnown forAdler–Bell–Jackiw anomalyJackiw–Teitelboim gravityTheta vacuumChildrenStefan JackiwNicholas JackiwAwardsDirac Medal (1998)Heine...

Not to be confused with Grand duchy. Territory ruled by, or representing the title of, a duke or duchess The Duke of Västergötland in 1930. A duchy, also called a dukedom, is a country, territory, fief, or domain ruled by a duke or duchess, a ruler hierarchically second to the king or queen in Western European tradition. There once existed an important difference between sovereign dukes and dukes who were ordinary noblemen throughout Europe. Some historic duchies were sovereign in areas tha...

 

غواصة يو-37 الجنسية  الإمبراطورية الألمانية المالك الإمبراطورية الألمانية المشغل البحرية الإمبراطورية الألمانية تعديل مصدري - تعديل   يو-37 هي غواصة تابعة للإمبراطورية الألمانية خدمت مع 329 غواصة في البحرية الإمبراطورية الألمانية أثناء الحرب العالمية الأولى.[1] شا�...