{"id":2223,"date":"2011-09-19T09:50:18","date_gmt":"2011-09-19T08:50:18","guid":{"rendered":"https:\/\/blogs.mentor.com\/colinwalls\/?p=2223"},"modified":"2026-03-26T16:35:50","modified_gmt":"2026-03-26T20:35:50","slug":"c-libraries","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/embedded-software\/2011\/09\/19\/c-libraries\/","title":{"rendered":"C libraries"},"content":{"rendered":"<p>For a software developer, the idea of a library is quite simple: It is a file containing a [typically large] number of functions\/procedures\/subroutines in a special format. At link time, the linker looks in the library [or there may well be more than one, in which case it checks each in turn] to resolve any references to functions not satisfied by the supplied object modules. This means that the programmer just needs to reference commonly used functions and their code is pulled in automatically.<\/p>\n<p>Of course, it is not quite that simple. Also, as with most aspects of embedded programming, libraries present more challenges and options to developers &#8230;<!--more--><\/p>\n<p>When developing software for the desktop, most programmers give little consideration to standard libraries, concentrating only on any special libraries that might be employed for their application. Such libraries are commonly dynamically linked, so they are quite different from anything used in most embedded systems.<\/p>\n<p>The fact that every embedded system is different is often cited [by <a href=\"https:\/\/blogs.mentor.com\/colinwalls\/blog\/2010\/01\/11\/small-or-fast\/\" target=\"_blank\" rel=\"noopener noreferrer\">me<\/a> anyway] as a reason for much of the complexity with developing embedded software. The use of libraries reflects this. Apart from getting a library that is right for the target device family and the chosen compiler, there may be a wide selection of other variations: chip family member specifics, register relative addressing, PC relative [position independent] code, endianity, size\/speed optimization, the list goes on &#8230;<\/p>\n<p>A standard C library contains two types of functions:<\/p>\n<ol>\n<li>Functions called by the generated code where the compiler has determined that so doing is preferable to creating inline instructions.<\/li>\n<li>Functions explicitly called by the code [like <strong>printf()<\/strong>].<\/li>\n<\/ol>\n<p>Commonly a single library is used to contain both these types of function. However, that is not always the case. For GNU compilers, one library [<strong>libgcc<\/strong>] contains the compiler support functions. There are a number of options to choose from for the explicitly called functions:<\/p>\n<ul>\n<li><strong>GLIBC<\/strong> is very full-featured and designed to be used with Linux, including not only the ISO C functions, but POSIX support and GNU extensions.<\/li>\n<li><strong>uClibc<\/strong> is also designed to be used with Linux [or uClinux] and contains a subset of <strong>GLIBC<\/strong>, so it has a smaller footprint.<\/li>\n<li><strong>Newlib<\/strong> is smaller still and is primarily aimed at embedded applications with no OS.<\/li>\n<\/ul>\n<p>An interesting question is: what is the benefit of a smaller library, given that only called functions are extracted from it so final binary image size will not vary? I can think of about three answers:<\/p>\n<ol>\n<li>A smaller library results in faster link time.<\/li>\n<li>Less choice of functions might make a programmer more careful in their selection, thus resulting in more optimal [smaller] code.<\/li>\n<li>A small library may also have smaller [less capable] versions of functions, which will result in a smaller application memory footprint.<\/li>\n<\/ol>\n<p>Any other ideas or suggestions would be welcome by comment or <a href=\"mailto:colin_walls@mentor.com\">email<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For a software developer, the idea of a library is quite simple: It is a file containing a [typically large]&#8230;<\/p>\n","protected":false},"author":71677,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[1],"tags":[313,339,300,427,307,340],"industry":[],"product":[],"coauthors":[],"class_list":["post-2223","post","type-post","status-publish","format-standard","hentry","category-news","tag-c","tag-development-tools","tag-embedded-software","tag-libraries","tag-linux","tag-programming-languages"],"_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/2223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/users\/71677"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/comments?post=2223"}],"version-history":[{"count":1,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/2223\/revisions"}],"predecessor-version":[{"id":9999,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/2223\/revisions\/9999"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/media?parent=2223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/categories?post=2223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/tags?post=2223"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/industry?post=2223"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/product?post=2223"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/coauthors?post=2223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}