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:

The UEFA Euro 2016 qualifying Group D was one of the nine groups to decide which teams would qualify for the UEFA Euro 2016 finals tournament.[1] Group D consisted of six teams: Germany, Republic of Ireland, Poland, Scotland, Georgia, and Gibraltar,[2] where they played against each other home-and-away in a round-robin format.[3] The top two teams, Germany and Poland, qualified directly for the finals. As third-placed Republic of Ireland weren't the highest-ranked amon...

 

Secondary route in Namibia This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: C13 road Namibia – news · newspapers · books · scholar · JSTOR (January 2017) (Learn how and when to remove this template message) C13 roadMajor junctionsSouth end B1 near the South African border at NoordoewerMajor intersections B4 at Aus C2...

 

يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (مارس 2016) هذه قائمة تحتوي على عصور علم الآثار. القارة الإقليم مقالات تحقيب الحقب الرئيسية أفريقيا شمال أفريقيا North Afri...

كامبو   لمعانٍ أخرى، طالع كامبو (توضيح). هذا المقال جزء من سلسلة عنالطب البديل والعلوم الزائفة معلومات عامة طب بديل طب بيطري بديل الدجل (الخداع الطبي) تاريخ الطب البديل تاريخ الطب العلوم الزائفة مناهضة العلم شكوكية شكوكية علمية المركز القومي للطب البديل والتكميلي مصطلح

 

Railway station in Fujikawaguchiko, Yamanashi Prefecture, Japan Fujikyu-Highland Station富士急ハイランド駅Fujikyu Highland Station entrance, July 2012General informationLocation6663 Funatsu, Fujikawaguchiko-machi, Minamitsuru-gun, Yamanashi-kenJapanCoordinates35°29′22″N 138°46′55″E / 35.48944°N 138.78194°E / 35.48944; 138.78194Elevation829 metersOperated by Fuji KyukoLine(s)■ Fujikyuko LineDistance25 km from ŌtsukiPlatforms1 side platformOther i...

 

  لمعانٍ أخرى، طالع ذا إكس فاكتور أرابيا (توضيح). إكس فاكتور الموسم الرابع أيضاً معروف باسم إكس فاكتور أرابيا التعليق شعار البرنامج النوع غنائي -مواهب - تفاعلي - ترفيه - واقع مبني على إكس فاكتور تقديم وائل منصور دانييلا رحمة باسل الزارو حكام راغب علامة إليسا دنيا سمير غا...

  لمعانٍ أخرى، طالع أندرويد (توضيح). روبوت الأندرويد هو الروبوت أو أي جسم صناعي تحاكي هيئته هيئة الإنسان بالإضافة إلى قيامه ببعض الوظائف كالتي يقوم بها البشر. أطلقت هذه التسمية في سنة 1270 من طرف ألبيرتوس ماغنوس[1] وانتشرت بعد ذلك بعد أن خلدها الروائي الفرنسي أوغوست د...

 

School in Ottawa, Ontario, CanadaYork Street Public SchoolAddress310 YorkOttawa, Ontario, K1N 5V3CanadaCoordinates45°25′55″N 75°40′58″W / 45.432063°N 75.682905°W / 45.432063; -75.682905InformationFounded1922School boardOttawa Carleton District School BoardPrincipalAndrew PostmaGradesJK-8LanguageEnglish, FrenchCampusurbanColour(s)  Red   White   BlackMascotMustangTeam nameMustangsCommunities servedLower Town Laurier/King Edward/Cobourg areaFee...

 

Sporting event delegationAndorra at the1984 Winter OlympicsIOC codeANDNOCAndorran Olympic CommitteeWebsite (in Catalan)in SarajevoCompetitors2 (men) in 1 sportFlag bearer Albert LloveraMedals Gold 0 Silver 0 Bronze 0 Total 0 Winter Olympics appearances (overview)1976198019841988199219941998200220062010201420182022 Andorra competed at the 1984 Winter Olympics in Sarajevo, Yugoslavia. Alpine skiing Main article: Alpine skiing at the 1984 Winter Olympics Men Athlete Event Race 1 Race 2...

American-born Australian academic (1943–2019) J. Bruce JacobsAMJacobs was awarded the Order of Brilliant Star in November 2018BornJeffrey Bruce Jacobs(1943-09-19)19 September 1943Died24 November 2019(2019-11-24) (aged 76)Melbourne, AustraliaAcademic backgroundEducationColumbia UniversityAcademic workDisciplineAsian studiesSub-disciplineTaiwan studiesInstitutionsMonash University J. Bruce Jacobs's voice Jacobs speaking in Mandarin Chinese about Tsai Ing-wen and the 1992 Consensus (from ...

 

This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Václav Vydra actor, born 1876 – news · newspapers · books · scholar · JSTOR (July 2011) (Learn how and when to remove this template message) Václav VydraBorn(1876-04-29)29 April 1876Plzeň, Austria-Hungary (now Czech Republic)Died7 April 1953(1953-04-07) (aged 76)Pra...

 

Naskah Tanjung Tanah dibersihkan secara simbolis dalam acara kenduri sko di Tanjung Tanah pada 13 Mei 2022 Naskah Tanjung Tanah adalah kitab undang-undang yang dikeluarkan oleh kerajaan Melayu pada abad ke-14. Naskah ini merupakan naskah Melayu yang tertua, dan juga satu-satunya yang tertulis dalam aksara Sumatera Kuno yang juga disebut sebagai aksara Malayu. Selain bahasa Melayu, naskah ini juga menggunakan bahasa Sanskerta.[1] Penemuan Naskah ini ditemukan di Tanjung Tanah di Mendap...

Indian Hindu saint Devraha BabaDeoraha Baba'sPersonalBornNot knownDeoria, IndiaDied19 June 1990 [1]Vrindavan, Uttar PradeshResting placeVrindavan, Uttar PradeshReligionHinduNationalityIndianTempleKuti Mandir Ram janki marg(Basti), Sugriv Qila (Ayodhya)Senior postingBased inIndiaSuccessorSri Purushottamacharyaji, Devdasji (Bade Sarkar), Devraha Hans Baba Devraha Baba (died 19 June 1990), was an Indian Siddha Yogi saint who lived beside the Yamuna river in Mathura. He was known as ...

 

19th century LDS Church Leader This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: John Taylor Mormon – news · newspapers · books · scholar · JSTOR (July 2019) (Learn how and when to remove this template message) John Taylor3rd President of the Church of Jesus Christ of Latter-day SaintsOctober 10,...

 

For other uses, see Lily of the valley (disambiguation). Species of flowering plant in the family Asparagaceae Lily of the valley Inflorescence Conservation status Least Concern (IUCN 3.1)[1] Scientific classification Kingdom: Plantae Clade: Tracheophytes Clade: Angiosperms Clade: Monocots Order: Asparagales Family: Asparagaceae Subfamily: Nolinoideae Genus: Convallaria Species: C. majalis Binomial name Convallaria majalisL. 19th-century illustration Lily of the valley (Conv...

Extraction of information from images via digital image processing techniques Not to be confused with Image processing. This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. Please help to improve this article by introducing more precise citations. (September 2013) (Learn how and when to remove this template message) Image analysis or imagery analysis is the extraction of meaningful information from im...

 

Some of this article's listed sources may not be reliable. Please help this article by looking for better, more reliable sources. Unreliable citations may be challenged or deleted. (April 2020) (Learn how and when to remove this template message) John Diva and the Rockets of LoveJohn Diva and the Rockets of Love in Bad Hindelang 2022Background informationOriginGermanyYears active2009-presentLabelsSPV / SteamhammerMembers John Diva Snake Rocket Remmie Martin J.J. Love Marcus Coolman jr. Past m...

 

Licence plates of Ontario, Canada OntarioCurrent seriesSloganYours to discover/Tant à découvrir[note 1]Size12 in × 6 in30 cm × 15 cmMaterialAluminumSerial formatABCD-123Introduced1997 (reissued in 2020) (1997 (reissued in 2020))AvailabilityIssued byMinistry of Transportation of OntarioManufactured byTrilcor IndustriesMilton, OntarioHistoryFirst issued1911 (1911)(pre-provincial plates from 1903 to 1911)vte The Canadian province of Ontario fir...

Kritikos Lagonikos Podenco de Creta en el Show Canino internacional de Atenas, octubre de 1997.Otros nombres podenco de Creta, en griego: Kρητικός Λαγωνικός, Kritikós LagonikósCaracterísticasTipo raza de perroTamaño macho 58–64 cm; hembra 50–58 cmPeso 15-22 kgPelaje corto, liso, duro, plano.[editar datos en Wikidata] El podenco de Creta (en griego: :Kρητικός Λαγωνικός [Kritikos Lagonikos]) es una raza de perro autóctona de la isla de Creta, G...

 

Military offensive 2017 Euphrates Crossing offensivePart of the Eastern Syria campaign and the Russian military intervention in the Syrian civil warDate18 September – 21 October 2017(1 month and 3 days)LocationEastern Syria Eastern Deir ez-Zor GovernorateStatus Syrian Army victory The Syrian Army captured ten villages after crossing the Euphrates River[1][2] The Syrian Army encircles the ISIL-held part of Deir ez-Zor cityBelligerents Syrian Arab Republic Syrian Arm...

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!