Are C libraries distributed with compilers or the OS itself?

According to my understanding, C libraries should be distributed with compilers. For example, GCC should distribute its own C library, and Forte should distribute its own C library. Do I understand correctly?

But can a user library compiled with GCC work with the Forte C library? If both C libraries are present on the system, which one will be called at runtime?

In addition, if an application links to several libraries compiled with GCC, and some with Forte, libraries compiled with GCC will automatically link to the GCC C library and behave similarly for Forte.

+6
source share
6 answers

GCC comes with libgcc, which includes helper functions for tasks such as long division (or even simpler things like multiplying by processors without a multiplication instruction). This does not require a specific libc implementation. FreeBSD uses the resulting BSD, glibc is very popular on Linux, and there are special ones for embedded systems like avr-libc.

Many libraries (libc, etc.) can be installed on systems, and the rules for choosing them depend on the OS. If you are linking statically, this is fully determined at compile time. If you link dynamically, the game uses version rules and paths. As a rule, you cannot mix and match at runtime due to the bits of the library (from the headers) that was compiled into the executable.

The compiled products of the two compilers must be compatible if they both follow the ABI for the platform. This is the goal of defining specific registration and calling agreements.

+7
source

As for Solaris, you're wrong. As the interface between the kernel and user territory, the standard C library is equipped with an operating system. This means that any C compiler you use (Forte / studio or gcc) always uses the same libc. In any case, the rare ports of the Cn (glibc) Gnu standard library for Solaris are quite limited and probably do not have too many functions that can be used. http://csclub.uwaterloo.ca/~dtbartle/opensolaris/

+3
source

None of the other answers (yet) mention an important function that facilitates the interworking between compilers and libraries - ABI or Application Binary Interface. On Unix-like machines, there is a well-documented ABI, and the C compilers in the system all follow the ABI. This allows a lot of mix. Usually you use the C system library, but you can use the replaceable version provided by the compiler, or created separately. And, as a rule, you can use a library compiled by one compiler with programs compiled by other compilers.

Sometimes a single compiler uses the runtime support library for some operations - perhaps 64-bit arithmetic routines on a 32-bit machine. If you use a library built with this compiler as part of a program created with another compiler, you may need to link this library. However, I have not seen this as a problem for a long time - with pure C.

C ++ binding is another matter. The same degree of interaction is not observed between different C ++ compilers - they do not agree with the details of the class layout (vtables, etc.), as well as how the exception handling is performed, etc. You need to work harder to create libraries created with one C ++ compiler that others can use.

+2
source

Only a few C library things are required in the sense that they are not needed for a standalone environment. It should only provide what is needed for the headlines.

<float.h>, <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and <stdint.h> 

Usually they do not implement the many functions that must be provided.

Other types of environments are called "hosted" environments. As the name implies, they suggest that there is some kind of entity that β€œlaunches” a running program, usually an OS. Thus, usually the C library is provided by this "hosting environment", but, as Ben said, there may be alternative implementations in different systems.

+1
source

Forte? It is really old.

Preferred compilers and development tools for Solaris are all contained in Oracle Solaris Studio. C / C ++ / Fortran with a debugger, performance analyzer and NetBeans IDE and many libraries.

http://www.oracle.com/technetwork/server-storage/solarisstudio/index.html

He is (still) free.

+1
source

I think there is a bit of confusion in terms: the library is NOT a DLL or .so: in the real sense of programming languages, libraries are compiled code that LINKER will combine with our binary (.o). Thus, the linker (or the compiler through some directives ...) can control them, but the OS cannot, it is simply NOT a concept related to the OS.

We are used to thinking that the OSs are written in C, and we can rebuild the OS using gcc / libraries or similar, but C is not linux / unix.

We can also have an OS written in Pascal (Mac OS was this way many years ago ..) and use libraries with our favorite C compiler, or have an OS written in ASM (even if not everything, like in the first Windows), but we must have C libraries to build exe.

0
source

Source: https://habr.com/ru/post/888381/


All Articles