Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler Libraries vs. Operating System Libraries

I noticed that both my compiler (MinGW) and the Windows 8 SDK come with the same libraries, save the naming conventions (i.e. win32.lib on the Windows 8 SDK is libwin32.a in the MinGW libraries).

  • Do all compilers come with libraries such as these?
  • Are these libraries for multiple operating systems?
  • What is the difference (if any) between the libraries that come with the Windows 8 SDK and those that come with the compiler?
like image 304
David Hackett Avatar asked May 12 '13 23:05

David Hackett


People also ask

What are operating system libraries?

System Library means anything that is normally distributed (in either source or binary form) with the major components (kernel, window system etc.) of the operating system(s) on which the Software or Modification runs, or a compiler used to produce the Object Code, or an object code interpreter used to run it.

Does operating system have compiler?

However, there are OS/machine independent compilers: most notably Java (and other JVM-based languages, such as Scala or Groovy). This is because Java compilers generate bytecode for the JVM, and are executed by the Java runtime (which is OS and processor specific).

Why are static libraries bigger?

Static libraries are much bigger in size, because external programs are built in the executable file. Dynamic libraries are much smaller, because there is only one copy of dynamic library that is kept in memory. Executable file will have to be recompiled if any changes were applied to external files.

What is static library C++?

Static Libraries. A static library contains object code linked with an end-user application, and then becomes part of that executable. A static library is sometimes called an archive since it is just a package of compiled object files. These libraries are in directories such as /lib, /usr/lib or /usr/local/lib.


1 Answers

There are two kinds of libraries:

  • Import libraries:
    These libraries only list where to find references to variables/functions/etc., but they don't contain the code itself.

  • "Normal" libraries (which contain object files that contain machine code):
    These libraries contain object files, which contain the actual machine code.

The libraries that ship with an operating system are generally import libraries.
The actual code, after all, is in the operating system itself; the import libraries merely tell you how to use the code provided in the operating system.
Why is this necessary? Because there is no way for a program to "discover" the libraries available on an operating system while it is running, so the program has to know what will be available when it is compiled.

Those that come with a compiler are generally code libraries; they contain code that the compiler requires (which varies depending on your particular compiler) in order to comple your program.

However, there is no single "standard format" for a library; Microsoft uses COFF, but *nix tools use ELF.
So when Microsoft ships the import libraries for a system, it only ships them in COFF format, which is great for the Visual C++ compiler -- but not so useful for other compilers.

This causes compiler vendors such as MinGW to be forced to create their own import libraries for the operating systems which they intended to target -- the purpose of these libraries is exactly the same as as those provided by the operating system vendor (such as Microsoft), but their format is different.

That's why you see seemingly similar libraries provided in multiple ways.

like image 116
user541686 Avatar answered Oct 06 '22 03:10

user541686